Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't pickle local object 'main.<locals>.grpc_prediction_server' #3410

Closed
minhdang241 opened this issue Jul 16, 2021 · 16 comments · Fixed by #4114
Closed

Can't pickle local object 'main.<locals>.grpc_prediction_server' #3410

minhdang241 opened this issue Jul 16, 2021 · 16 comments · Fixed by #4114
Assignees
Labels

Comments

@minhdang241
Copy link

minhdang241 commented Jul 16, 2021

Describe the bug

I have follow the tutorial here and got the error as

2021-07-16 13:45:27,155 - seldon_core.microservice:main:203 - INFO:  Starting microservice.py:main
2021-07-16 13:45:27,155 - seldon_core.microservice:main:204 - INFO:  Seldon Core version: 1.9.1
2021-07-16 13:45:27,159 - seldon_core.microservice:main:345 - INFO:  Parse JAEGER_EXTRA_TAGS []
2021-07-16 13:45:27,160 - seldon_core.microservice:main:348 - INFO:  Annotations: {}
2021-07-16 13:45:27,160 - seldon_core.microservice:main:352 - INFO:  Importing MyModel
2021-07-16 13:45:28,526 - seldon_core.microservice:main:396 - INFO:  REST microservice running on port 9000 single-threaded=0
2021-07-16 13:45:28,526 - seldon_core.microservice:main:486 - INFO:  REST metrics microservice running on port 6000
2021-07-16 13:45:28,527 - seldon_core.microservice:main:496 - INFO:  Starting servers
Traceback (most recent call last):
  File "/Users/minhdang/opt/miniconda3/envs/datascience/bin/seldon-core-microservice", line 8, in <module>
    sys.exit(main())
  File "/Users/minhdang/opt/miniconda3/envs/datascience/lib/python3.9/site-packages/seldon_core/microservice.py", line 497, in main
    start_servers(server1_func, server2_func, server3_func, metrics_server_func)
  File "/Users/minhdang/opt/miniconda3/envs/datascience/lib/python3.9/site-packages/seldon_core/microservice.py", line 64, in start_servers
    p2.start()
  File "/Users/minhdang/opt/miniconda3/envs/datascience/lib/python3.9/multiprocessing/process.py", line 121, in start
    self._popen = self._Popen(self)
  File "/Users/minhdang/opt/miniconda3/envs/datascience/lib/python3.9/multiprocessing/context.py", line 224, in _Popen
    return _default_context.get_context().Process._Popen(process_obj)
  File "/Users/minhdang/opt/miniconda3/envs/datascience/lib/python3.9/multiprocessing/context.py", line 284, in _Popen
    return Popen(process_obj)
  File "/Users/minhdang/opt/miniconda3/envs/datascience/lib/python3.9/multiprocessing/popen_spawn_posix.py", line 32, in __init__
    super().__init__(process_obj)
  File "/Users/minhdang/opt/miniconda3/envs/datascience/lib/python3.9/multiprocessing/popen_fork.py", line 19, in __init__
    self._launch(process_obj)
  File "/Users/minhdang/opt/miniconda3/envs/datascience/lib/python3.9/multiprocessing/popen_spawn_posix.py", line 47, in _launch
    reduction.dump(process_obj, fp)
  File "/Users/minhdang/opt/miniconda3/envs/datascience/lib/python3.9/multiprocessing/reduction.py", line 60, in dump
    ForkingPickler(file, protocol).dump(obj)
AttributeError: Can't pickle local object 'main.<locals>.grpc_prediction_server'

Environment

OS: MacOS
Python version: 3.9.5

@minhdang241 minhdang241 added bug triage Needs to be triaged and prioritised accordingly labels Jul 16, 2021
@ukclivecox
Copy link
Contributor

ukclivecox commented Jul 29, 2021

I see you are using python 3.9 see #1230

Can you try with python 3.7 for your use case?

@ukclivecox ukclivecox added awaiting-feedback and removed triage Needs to be triaged and prioritised accordingly labels Jul 29, 2021
@damosuzuki
Copy link

FYI: Reading the linked issue, it seems that Python 3.8 support has been merged, but I am still facing the same error reported above on 3.8.5.

@ukclivecox
Copy link
Contributor

Thanks @damosuzuki can you give any further insight into the issue?

@damosuzuki
Copy link

damosuzuki commented Oct 1, 2021

Not sure I have more insight, but I can be more verbose :)

I am trying to follow the same instructions as @minhdang241 (https://docs.seldon.io/projects/seldon-core/en/v1.1.0/python/python_component.html), and I receive the same error when trying to start the example model with seldon-core-microservice with Python 3.8.5 (macos). I noticed that #1230 adds support for Python 3.8, but I am not sure if this impacts seldon-core-microservice.

@damosuzuki
Copy link

I see now that seldon-core-microservice is used in s2i which is now on Python 3.8 by default. I wonder if this is a MacOS specific issue.

@ukclivecox
Copy link
Contributor

Please reopen if still an issue on MacOS

@kfleischmann
Copy link

Have the same problem. Can i support to debug this issue?

@ukclivecox
Copy link
Contributor

Thanks. Do you have any further logs or insights here @kfleischmann

@jeremy-london
Copy link

jeremy-london commented Jan 19, 2022

Hitting this error on Python 3.9.9 using MacOS Big Sur 11.6.2

2022-01-19 11:05:30,987 - seldon_core.microservice:main:567 - INFO:  Starting servers
Traceback (most recent call last):
  File "/Users/e346901/Projects/Gitlab/dai/radlab/irad/mlops-irad/workspaces/s92-nlp/env/bin/seldon-core-microservice", line 8, in <module>
    sys.exit(main())
  File "/env/lib/python3.9/site-packages/seldon_core/microservice.py", line 568, in main
    start_servers(server1_func, server2_func, server3_func, metrics_server_func)
  File "/env/lib/python3.9/site-packages/seldon_core/microservice.py", line 72, in start_servers
    p2.start()
  File "/usr/local/Cellar/[email protected]/3.9.9/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/process.py", line 121, in start
    self._popen = self._Popen(self)
  File "/usr/local/Cellar/[email protected]/3.9.9/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/context.py", line 224, in _Popen
    return _default_context.get_context().Process._Popen(process_obj)
  File "/usr/local/Cellar/[email protected]/3.9.9/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/context.py", line 284, in _Popen
    return Popen(process_obj)
  File "/usr/local/Cellar/[email protected]/3.9.9/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/popen_spawn_posix.py", line 32, in __init__
    super().__init__(process_obj)
  File "/usr/local/Cellar/[email protected]/3.9.9/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/popen_fork.py", line 19, in __init__
    self._launch(process_obj)
  File "/usr/local/Cellar/[email protected]/3.9.9/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/popen_spawn_posix.py", line 47, in _launch
    reduction.dump(process_obj, fp)
  File "/usr/local/Cellar/[email protected]/3.9.9/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/reduction.py", line 60, in dump
    ForkingPickler(file, protocol).dump(obj)
AttributeError: Can't pickle local object 'main.<locals>.grpc_prediction_server'

Also seeing this error on Python 3.8.9 using MacOS Big Sur 11.6.2

2022-01-19 13:06:28,726 - seldon_core.microservice:main:567 - INFO:  Starting servers
Traceback (most recent call last):
  File "/env/bin/seldon-core-microservice", line 8, in <module>
    sys.exit(main())
  File "/env/lib/python3.8/site-packages/seldon_core/microservice.py", line 568, in main
    start_servers(server1_func, server2_func, server3_func, metrics_server_func)
  File "/env/lib/python3.8/site-packages/seldon_core/microservice.py", line 72, in start_servers
    p2.start()
  File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/multiprocessing/process.py", line 121, in start
    self._popen = self._Popen(self)
  File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/multiprocessing/context.py", line 224, in _Popen
    return _default_context.get_context().Process._Popen(process_obj)
  File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/multiprocessing/context.py", line 284, in _Popen
    return Popen(process_obj)
  File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/multiprocessing/popen_spawn_posix.py", line 32, in __init__
    super().__init__(process_obj)
  File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/multiprocessing/popen_fork.py", line 19, in __init__
    self._launch(process_obj)
  File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/multiprocessing/popen_spawn_posix.py", line 47, in _launch
    reduction.dump(process_obj, fp)
  File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/multiprocessing/reduction.py", line 60, in dump
    ForkingPickler(file, protocol).dump(obj)
AttributeError: Can't pickle local object 'main.<locals>.grpc_prediction_server'

@simanto604newscred
Copy link

Facing same with 3.9

@RuiLi-5413
Copy link

Same error with 3.8.6

@RafalSkolasinski
Copy link
Contributor

Did anyone manage to reproduce issue in Linux environment?

@gerilya
Copy link

gerilya commented May 22, 2022

It looks like it's related to the way multiprocessing is implemented on MacOs and is the same issue as reported here: pydoit/doit#372

I've checked the PR which resolves it and modified microservice.py as follows:
Replaced the following line:
import multiprocess as mp
With the following lines:

try:
        import multiprocess as mp
        HAS_MULTIPROCESS = True
except ImportError:
        import multiprocessing as mp

That fixed the issue for me. I have multiprocess 0.70.12.2 installed.

@ukclivecox
Copy link
Contributor

This is great - thanks @gerilya - we can include this in the next release @RafalSkolasinski

@RafalSkolasinski
Copy link
Contributor

Nice. However, rather then defaulting to the multiprocess library if it is installed I would suggest to have it driven by an environmental variable.

@RafalSkolasinski RafalSkolasinski self-assigned this May 23, 2022
@RafalSkolasinski
Copy link
Contributor

@gerilya We have a PR containing a fix for this: #4114. The behaviour is controlled via environmental variable.
You should be able to set USE_MULTIPROCESS_PACKAGE=true now in order to do local testing on MacOS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants