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
buffer objects are picklable but result is not unpicklable #52570
Comments
The multiprocessing module's version of the Queue class, which causes objects to be pickled for process to process transfer, ignores pickle restrictions when objects are added to the queue. Example code (buffer isn't pickleable): from multiprocessing import Queue
q = Queue()
q.put(buffer("this is a buffer"))
print(q.get()) It results in an exception, which is expected, but the exception is confusing, after the problem has already occurred, and if I were actually using multiple processes, not in the process that tried to send an unsendable object: Traceback (most recent call last):
File "mppkbuffer.py", line 5, in <module>
print(q.get())
File "/usr/lib/python2.6/multiprocessing/queues.py", line 91, in get
res = self._recv()
TypeError: buffer() takes at least 1 argument (0 given) Expected result would be a thrown exception when we attempt to put the object into the queue using .put(), NOT when we attempt pull it out of the queue using .get(), when it gets unpickled. Basically, while pickle fails when it tries to dump, Queue succeeds the dump (somehow) and fails to load. I have tested with python 2.6.4 and 2.7a4. 3.1 doesn't appear to have this bug (but it does have a different one which I will report later). |
Since these sort of buffer objects don't exist in 3.x (so far as I know), I came up with a different way to test in 3.x (basically, trying to pickle bound or unbound methods). It turns out that using this method to test it in 2.6 seems to fail where it should (in .put()), so if there's some sort of object that isn't pickleable in the same way as buffer that exists in 3.x, it should be tested to see if this specific problem is actually confined to 2.6 or not. |
Buffer objects *are* picklable with protocol 2 (but not with earlier protocols). Unfortunately, the result is not unpicklable. This is not a problem with multiprocessing. (buffer seems to inherit __reduce__ and __reduce_ex__ from object.) Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53)
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cPickle
>>> cPickle.dumps(buffer("hello"), cPickle.HIGHEST_PROTOCOL)
'\x80\x02c__builtin__\nbuffer\nq\x01)\x81q\x02.'
>>> cPickle.loads(_)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: buffer() takes at least 1 argument (0 given) |
It seems the real issue here is that buffer objects are picklable (depending on protocol) but the resulting string is not unpicklable. There are probably lots of other examples where this happens: for instance Exception subclasses which do not set self.args correctly (see Issue bpo-1692335). buffer is only used in Python 2.x. Python 2.7 is in bugfix mode, so this issue will not change now. I will close this issue as "won't fix". |
While buffer is only used in Python 2.x, there is a similar issue in 3.x with memoryview. The patch for bpo-22995 fixes this issue. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: