-
-
Notifications
You must be signed in to change notification settings - Fork 328
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 trio
as a package
#2135
Comments
This patch seems to work, do you want me to PR as a method? import trio
import pickle
def __reduce__(self):
return (self.__class__, tuple())
trio._deprecate._ModuleWithDeprecations.__reduce__ = __reduce__
pickle.dumps(trio._deprecate._ModuleWithDeprecations("hello")) |
It's an internal implementation detail whether any given module is a |
...Actually, I'm getting a bit confused about cloudpickle here -- I get Can you show your real code that's failing, or at least the real traceback? |
For example, import ray
import trio
ray.init()
@ray.remote
def task():
async def sleeper():
await trio.sleep(1)
trio.run(sleeper)
task.remote() This gives: /root/.local/share/virtualenvs/moozi-g1CZ00E9/lib/python3.8/site-packages/trio/_core/_multierror.py:511: RuntimeWarning: You seem to already have a custom sys.excepthook handler installed. I'll skip installing Trio's custom handler, but this means MultiErrors will not show full tracebacks.
warnings.warn(
2021-10-05 06:28:59,438 INFO services.py:1250 -- View the Ray dashboard at http://127.0.0.1:8266
Traceback (most recent call last):
File "scripts/trio_pickle.py", line 12, in <module>
task.remote()
File "/root/.local/share/virtualenvs/moozi-g1CZ00E9/lib/python3.8/site-packages/ray/remote_function.py", line 123, in _remote_proxy
return self._remote(args=args, kwargs=kwargs)
File "/root/.local/share/virtualenvs/moozi-g1CZ00E9/lib/python3.8/site-packages/ray/util/tracing/tracing_helper.py", line 293, in _invocation_remote_span
return method(self, args, kwargs, *_args, **_kwargs)
File "/root/.local/share/virtualenvs/moozi-g1CZ00E9/lib/python3.8/site-packages/ray/remote_function.py", line 252, in _remote
self._pickled_function = pickle.dumps(self._function)
File "/root/.local/share/virtualenvs/moozi-g1CZ00E9/lib/python3.8/site-packages/ray/cloudpickle/cloudpickle_fast.py", line 73, in dumps
cp.dump(obj)
File "/root/.local/share/virtualenvs/moozi-g1CZ00E9/lib/python3.8/site-packages/ray/cloudpickle/cloudpickle_fast.py", line 580, in dump
return Pickler.dump(self, obj)
TypeError: cannot pickle '_ModuleWithDeprecations' object Moving the import statement into the remote actor seems to solve the problem, but seems too hacky? import ray
ray.init()
@ray.remote
def task():
import trio
async def sleeper():
await trio.sleep(1)
trio.run(sleeper)
task.remote() This works. |
gives
This is problematic for serializing objects that have methods that use trio somehow.
The text was updated successfully, but these errors were encountered: