-
Notifications
You must be signed in to change notification settings - Fork 164
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
Cannot pickle lock objects #81
Comments
FWIW tried this with >>> import dill
>>> import threading
>>> l = threading.Lock()
>>> dill.dumps(l)
'\x80\x02cdill.dill\n_create_lock\nq\x00\x89\x85q\x01Rq\x02.' |
An interesting related anecdote is using >>> import multiprocessing
>>> import cloudpickle
>>> import dill
>>> l = multiprocessing.Lock()
>>> cloudpickle.dumps(l)
'\x80\x02'
>>> dill.dumps(l)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/zopt/conda2/envs/pickle_test/lib/python2.7/site-packages/dill/dill.py", line 259, in dumps
dump(obj, file, protocol, byref, fmode, recurse)#, strictio)
File "/zopt/conda2/envs/pickle_test/lib/python2.7/site-packages/dill/dill.py", line 252, in dump
pik.dump(obj)
File "/zopt/conda2/envs/pickle_test/lib/python2.7/pickle.py", line 224, in dump
self.save(obj)
File "/zopt/conda2/envs/pickle_test/lib/python2.7/pickle.py", line 306, in save
rv = reduce(self.proto)
File "/zopt/conda2/envs/pickle_test/lib/python2.7/multiprocessing/synchronize.py", line 95, in __getstate__
assert_spawning(self)
File "/zopt/conda2/envs/pickle_test/lib/python2.7/multiprocessing/forking.py", line 52, in assert_spawning
' through inheritance' % type(self).__name__
RuntimeError: Lock objects should only be shared between processes through inheritance |
cc @mrocklin |
I'm generally against serializing normal locks. It is a dangerous thing to
do without understanding what the lock is trying to protect. That being
said, you might want to try dask.utils.SerializableLock.
…On Wed, Feb 15, 2017 at 3:23 PM, jakirkham ***@***.***> wrote:
cc @mrocklin <https://github.com/mrocklin>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#81 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AASszKHcv_q1qliSliwvpy4cmv944Tccks5rc17fgaJpZM4MCLKr>
.
|
I think I agree. Hence the statement, "not sure if this is something that should be permissible or not". Also the reason for cc-ing you. That said, I think we could do better here than say failing because RuntimeError: Lock objects should only be shared between processes through inheritance
Yep, that was what I was going to try. 😄 |
Should we close this? |
So we are allowing pickling of |
Where is that? I don't see any explicit code for that. |
Please see the code snippet in the details of this comment for an example of this behavior. |
The pickling is obviously bogus (a 2-byte string cannot hold the necessary information for unpickling):
The question is: should we special-case all types for which we want to disallow pickling, such that people get an error message? That might be an endless task... |
I'm confused by this question. >>> import pickle
>>> import multiprocessing
>>> l = multiprocessing.Lock()
>>> pickle.dumps(l)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/zopt/conda2/envs/pickle_test/lib/python2.7/pickle.py", line 1380, in dumps
Pickler(file, protocol).dump(obj)
File "/zopt/conda2/envs/pickle_test/lib/python2.7/pickle.py", line 224, in dump
self.save(obj)
File "/zopt/conda2/envs/pickle_test/lib/python2.7/pickle.py", line 306, in save
rv = reduce(self.proto)
File "/zopt/conda2/envs/pickle_test/lib/python2.7/copy_reg.py", line 84, in _reduce_ex
dict = getstate()
File "/zopt/conda2/envs/pickle_test/lib/python2.7/multiprocessing/synchronize.py", line 95, in __getstate__
assert_spawning(self)
File "/zopt/conda2/envs/pickle_test/lib/python2.7/multiprocessing/forking.py", line 52, in assert_spawning
' through inheritance' % type(self).__name__
RuntimeError: Lock objects should only be shared between processes through inheritance |
I'm wondering what makes |
Launching these commands on Python 3.6.12 |Anaconda, Inc.| (default, Sep 8 2020, 23:10:56)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.16.1 -- An enhanced Interactive Python. Type '?' for help.
In [1]: import cloudpickle
In [2]: import multiprocessing
In [3]: cloudpickle.dumps(multiprocessing.Lock())
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-3-5671a97d518f> in <module>
----> 1 cloudpickle.dumps(multiprocessing.Lock())
~/.local/miniconda3/envs/py36/lib/python3.6/site-packages/cloudpickle/cloudpickle_fast.py in dumps(obj, protocol)
100 with io.BytesIO() as file:
101 cp = CloudPickler(file, protocol=protocol)
--> 102 cp.dump(obj)
103 return file.getvalue()
104
~/.local/miniconda3/envs/py36/lib/python3.6/site-packages/cloudpickle/cloudpickle_fast.py in dump(self, obj)
561 def dump(self, obj):
562 try:
--> 563 return Pickler.dump(self, obj)
564 except RuntimeError as e:
565 if "recursion" in e.args[0]:
~/.local/miniconda3/envs/py36/lib/python3.6/pickle.py in dump(self, obj)
407 if self.proto >= 4:
408 self.framer.start_framing()
--> 409 self.save(obj)
410 self.write(STOP)
411 self.framer.end_framing()
~/.local/miniconda3/envs/py36/lib/python3.6/pickle.py in save(self, obj, save_persistent_id)
494 reduce = getattr(obj, "__reduce_ex__", None)
495 if reduce is not None:
--> 496 rv = reduce(self.proto)
497 else:
498 reduce = getattr(obj, "__reduce__", None)
~/.local/miniconda3/envs/py36/lib/python3.6/multiprocessing/synchronize.py in __getstate__(self)
99
100 def __getstate__(self):
--> 101 context.assert_spawning(self)
102 sl = self._semlock
103 if sys.platform == 'win32':
~/.local/miniconda3/envs/py36/lib/python3.6/multiprocessing/context.py in assert_spawning(obj)
354 raise RuntimeError(
355 '%s objects should only be shared between processes'
--> 356 ' through inheritance' % type(obj).__name__
357 )
RuntimeError: Lock objects should only be shared between processes through inheritance |
Maybe this got fixed at some point then? Edit: Do we have a test covering that? |
James just added PR ( #449 ) with a test cover this case. Have gone ahead and merged since it seems like we are ok with the current behavior. Though please let us know if that is not the case |
Encountering issues trying to pickle lock objects. Not sure if this is something that should be permissible or not. Seems
cloudpickle
just falls back topickle
in this case. Traceback shown below.The text was updated successfully, but these errors were encountered: