diff options
author | nat-goodspeed <nat@lindenlab.com> | 2016-12-04 14:55:58 -0500 |
---|---|---|
committer | Sergey Shepelev <temotor@gmail.com> | 2016-12-04 22:55:58 +0300 |
commit | f572fc9ae202bfda1098326b0134eb2ab5452bce (patch) | |
tree | f70932fa2d9c41ee37f9fe418e5f6dc866cdb130 | |
parent | 32e2c335fbbcf854c856784c6b07357eb46a8d37 (diff) | |
download | eventlet-f572fc9ae202bfda1098326b0134eb2ab5452bce.tar.gz |
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
-rw-r--r-- | eventlet/dagpool.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/eventlet/dagpool.py b/eventlet/dagpool.py index 3002e44..618abf2 100644 --- a/eventlet/dagpool.py +++ b/eventlet/dagpool.py @@ -38,12 +38,19 @@ class PropagateError(Exception): the exception object raised by the greenthread """ 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.exc = exc def __str__(self): - return "PropagateError({0}): {1}: {2}" \ - .format(self.key, self.exc.__class__.__name__, self.exc) + return self.msg class DAGPool(object): |