Skip to content

Commit c22372f

Browse files
committed
add MaybeDecodingError
1 parent be61dc5 commit c22372f

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

Lib/multiprocessing/pool.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,22 @@ def rebuild_exc(exc, tb):
7777
# Code run by worker processes
7878
#
7979

80+
class MaybeDecodingError(Exception):
81+
"""Wraps possible unpickleable errors, so they can be
82+
safely sent through the socket."""
83+
84+
def __init__(self, exc):
85+
self.exc = repr(exc)
86+
self.__cause__ = exc
87+
super(MaybeDecodingError, self).__init__(self.exc)
88+
89+
def __str__(self):
90+
return "Error receiving result. Reason: '%s'" % (self.exc,
91+
self.exc)
92+
93+
def __repr__(self):
94+
return "<%s: %s>" % (self.__class__.__name__, self)
95+
8096
class MaybeEncodingError(Exception):
8197
"""Wraps possible unpickleable errors, so they can be
8298
safely sent through the socket."""
@@ -586,11 +602,7 @@ def _handle_tasks(taskqueue, put, outqueue, pool, cache):
586602
@staticmethod
587603
def _handle_results(outqueue, get, cache):
588604
def _handle_results_failure(cache, e):
589-
exc = RuntimeError("Result handler failed to get result from worker and " +
590-
"unable to recover. " +
591-
"This is likely due to a worker process return or raise " +
592-
"an unpicklable object.")
593-
exc.__cause__ = e
605+
exc = MaybeDecodingError(e)
594606
cache._disable_cache(exc)
595607
_cache = cache.copy()
596608
for value in _cache.values():

0 commit comments

Comments
 (0)