You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
multiprocessing.pool: Worker crashes if result can't be encoded #53490
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:
assignee=Noneclosed_at=<Date2012-05-25.19:55:25.007>created_at=<Date2010-07-13.11:51:53.667>labels= ['type-bug', 'library']
title="multiprocessing.pool: Worker crashes if result can't be encoded"updated_at=<Date2012-05-25.19:55:25.005>user='https://bugs.python.org/asksol'
If the target function returns an unpickleable value the worker process crashes. This patch tries to safely handle unpickleable errors, while enabling the user to inspect such errors after the fact.
In addition a new argument has been added to apply_async: error_callback.
This is an optional callback that is called if the job raises an exception. The signature of the callback is callback(exc).
changed the title [-]multiprocessing.pool: Pool crashes if worker can't encode result (with patch)[/-][+]multiprocessing.pool: Worker crashes if result can't be encoded result (with patch)[/+]on Jul 13, 2010
changed the title [-]multiprocessing.pool: Worker crashes if result can't be encoded result (with patch)[/-][+]multiprocessing.pool: Worker crashes if result can't be encoded[/+]on Jul 13, 2010
This looks pretty reasonable to my untrained eye. I successfully applied and ran the test suite.
To be clear, the errback change and the unpickleable result change are actually orthogonal, right? Anyway, I'm not really familiar with the protocol here, but assuming that you're open to code review:
def test_async_timeout(self):
In general, I'm wary of nonessential whitespace changes... did you mean to include these?
scratchpad = [None]
def errback(exc):
scratchpad[0] = exc
res = p.apply_async(raising, error_callback=errback)
self.assertRaises(KeyError, res.get)
self.assertTrue(scratchpad[0])
self.assertIsInstance(scratchpad[0], KeyError)
p.close()
Using "assertTrue" seems misleading. "assertIsNotNone" is what you really mean, right? Although, I believe that's redundant, since presumably self.assertIsInstance(None, KeyError) will error out anyway (I haven't verified this).
def test_unpickleable_result(self):
from multiprocessing.pool import MaybeEncodingError
p = multiprocessing.Pool(2)
# Make sure we don't lose pool processes because of encoding errors.
for iteration in xrange(20):
scratchpad = [None]
def errback(exc):
scratchpad[0] = exc
res = p.apply_async(unpickleable_result, error_callback=errback)
self.assertRaises(MaybeEncodingError, res.get)
wrapped = scratchpad[0]
self.assertTrue(wrapped)
Again, assertTrue is probably not what you want, and is probably redundant.
Under what circumstances would these be None? (Perhaps you want wrapped.exc != 'None'?) The initializer for MaybeEncodingError enforces the invariant that exc/value are strings, right?
class _TestPoolWorkerLifetime(BaseTestCase):
ALLOWED_TYPES = ('processes', )
Three line breaks there seems excessive.
asksol commented on Jul 14, 2010
asksolmannequin
MannequinAuthor
More actions
To be clear, the errback change and the unpickleable result
change are actually orthogonal, right?
Yes, it could be a separate issue. Jesse, do you think I should I open
up a separate issue for this?
Why not add an error_callback for map_async as well?
That's a good idea!
Any reason you chose to use a different internal name
(errback versus error_callback)? It seems cleaner to me
to be consistent about the name.
It was actually a mistake. The argument was errback before, so
it's just a leftover from the previous name.
In general, I'm wary of nonessential whitespace changes...
did you mean to include these?
Of course not.
Using "assertTrue" seems misleading. "assertIsNotNone" is what
really mean, right? Although, I believe that's redundant,
since presumably self.assertIsInstance(None, KeyError) will
error out anyway (I haven't verified this).
bool(KeyError("foo")) is True and bool(None) is False, so it works either way. It could theoretically result in a false negative if
the exception class tested overrides __nonzero__, but that is unlikely
to happen as the target always returns KeyError anyway (and the test below ensures it) It's just a habit of mine, unless I really want to test for Noneness, I just use assertTrue, but I'm not against changing it to assertIsNotNone either.
Under what circumstances would these be None? (Perhaps you
want wrapped.exc != 'None'?) The initializer for
MaybeEncodingError enforces the invariant that exc/value are strings
right?
It's just to test that these are actually set to something.
Even an empty string passes with assertIsNone instead of assertTrue.
Maybe it's better to test the values set, but I didn't bother.
Activity
asksol commentedon Jul 13, 2010
If the target function returns an unpickleable value the worker process crashes. This patch tries to safely handle unpickleable errors, while enabling the user to inspect such errors after the fact.
In addition a new argument has been added to apply_async: error_callback.
This is an optional callback that is called if the job raises an exception. The signature of the callback is
callback(exc).[-]multiprocessing.pool: Pool crashes if worker can't encode result (with patch)[/-][+]multiprocessing.pool: Worker crashes if result can't be encoded result (with patch)[/+][-]multiprocessing.pool: Worker crashes if result can't be encoded result (with patch)[/-][+]multiprocessing.pool: Worker crashes if result can't be encoded[/+]gdb commentedon Jul 13, 2010
This looks pretty reasonable to my untrained eye. I successfully applied and ran the test suite.
To be clear, the errback change and the unpickleable result change are actually orthogonal, right? Anyway, I'm not really familiar with the protocol here, but assuming that you're open to code review:
Sure. Why not add an error_callback for map_async as well?
Any reason you chose to use a different internal name (errback versus error_callback)? It seems cleaner to me to be consistent about the name.
Using "assertTrue" seems misleading. "assertIsNotNone" is what you really mean, right? Although, I believe that's redundant, since presumably self.assertIsInstance(None, KeyError) will error out anyway (I haven't verified this).
Again, assertTrue is probably not what you want, and is probably redundant.
Why use scratchpad[0] rather than wrapped?
Under what circumstances would these be None? (Perhaps you want wrapped.exc != 'None'?) The initializer for MaybeEncodingError enforces the invariant that exc/value are strings, right?
Three line breaks there seems excessive.
asksol commentedon Jul 14, 2010
Yes, it could be a separate issue. Jesse, do you think I should I open
up a separate issue for this?
That's a good idea!
It was actually a mistake. The argument was
errbackbefore, soit's just a leftover from the previous name.
Of course not.
bool(KeyError("foo")) is True and bool(None) is False, so it works either way. It could theoretically result in a false negative if
the exception class tested overrides __nonzero__, but that is unlikely
to happen as the target always returns KeyError anyway (and the test below ensures it) It's just a habit of mine, unless I really want to test for Noneness, I just use assertTrue, but I'm not against changing it to assertIsNotNone either.
asksol commentedon Jul 15, 2010
Updated patch with Greg's suggestions.
(multiprocessing-trunk@82502-handle_worker_encoding_errors2.patch)
jnoller commentedon Nov 5, 2010
Fine w/ committing this Ask.
python-dev commentedon May 2, 2012
New changeset 26bbff4562a7 by Richard Oudkerk in branch '2.7':
Issue bpo-9400: Partial backport of fix for bpo-9244
http://hg.python.org/cpython/rev/26bbff4562a7
sbt commentedon May 25, 2012
The patch was applied to 3.x branch in 0aa8af79359d and partially backported to 2.7 in 26bbff4562a7 - see bpo-9400.
I will close.