dagpool: PropagateError was not compatible with pickle
Previous PropagateError.__init__() failed to call Exception.__init__() at all. Moreover, as described in https://bugs.python.org/issue1692335, setting self.args is important for an Exception subclass with nonstandard constructor arguments. When an Exception subclass sets self.args, it makes the subclass pickleable -- but instead of str(instance) returning the string passed to Exception.__init__(), it instead returns the string representation of self.args. So capture the message string, and in addition to passing it to Exception.__init__(), also override __str__() and return the same string. https://github.com/eventlet/eventlet/pull/359
This commit is contained in:

committed by
Sergey Shepelev

parent
32e2c335fb
commit
f572fc9ae2
@@ -38,12 +38,19 @@ class PropagateError(Exception):
|
|||||||
the exception object raised by the greenthread
|
the exception object raised by the greenthread
|
||||||
"""
|
"""
|
||||||
def __init__(self, key, exc):
|
def __init__(self, key, exc):
|
||||||
|
# initialize base class with a reasonable string message
|
||||||
|
msg = "PropagateError({0}): {1}: {2}" \
|
||||||
|
.format(key, exc.__class__.__name__, exc)
|
||||||
|
super(PropagateError, self).__init__(msg)
|
||||||
|
self.msg = msg
|
||||||
|
# Unless we set args, this is unpickleable:
|
||||||
|
# https://bugs.python.org/issue1692335
|
||||||
|
self.args = (key, exc)
|
||||||
self.key = key
|
self.key = key
|
||||||
self.exc = exc
|
self.exc = exc
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "PropagateError({0}): {1}: {2}" \
|
return self.msg
|
||||||
.format(self.key, self.exc.__class__.__name__, self.exc)
|
|
||||||
|
|
||||||
|
|
||||||
class DAGPool(object):
|
class DAGPool(object):
|
||||||
|
Reference in New Issue
Block a user