diff options
author | Richard Oudkerk <shibturn@gmail.com> | 2013-05-06 10:38:25 (GMT) |
---|---|---|
committer | Richard Oudkerk <shibturn@gmail.com> | 2013-05-06 10:38:25 (GMT) |
commit | 8575783a00a6fc7ef9cb754df90532b178de2fb3 (patch) | |
tree | 20f726521104969868978503e8f5da420ce2555c /Lib/multiprocessing/pool.py | |
parent | 53683f6f4bc53a0ffad923a0e056e488dc7dbb6f (diff) | |
download | cpython-8575783a00a6fc7ef9cb754df90532b178de2fb3.zip cpython-8575783a00a6fc7ef9cb754df90532b178de2fb3.tar.gz cpython-8575783a00a6fc7ef9cb754df90532b178de2fb3.tar.bz2 |
Issue #13813: Embed stringification of remote traceback in local
traceback raised when pool task raises an exception.
Diffstat (limited to 'Lib/multiprocessing/pool.py')
-rw-r--r-- | Lib/multiprocessing/pool.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/Lib/multiprocessing/pool.py b/Lib/multiprocessing/pool.py index c0aa717..82a2923 100644 --- a/Lib/multiprocessing/pool.py +++ b/Lib/multiprocessing/pool.py @@ -18,6 +18,7 @@ import queue import itertools import collections import time +import traceback from multiprocessing import Process, cpu_count, TimeoutError from multiprocessing.util import Finalize, debug @@ -43,6 +44,29 @@ def starmapstar(args): return list(itertools.starmap(args[0], args[1])) # +# Hack to embed stringification of remote traceback in local traceback +# + +class RemoteTraceback(Exception): + def __init__(self, tb): + self.tb = tb + def __str__(self): + return self.tb + +class ExceptionWithTraceback: + def __init__(self, exc, tb): + tb = traceback.format_exception(type(exc), exc, tb) + tb = ''.join(tb) + self.exc = exc + self.tb = '\n"""\n%s"""' % tb + def __reduce__(self): + return rebuild_exc, (self.exc, self.tb) + +def rebuild_exc(exc, tb): + exc.__cause__ = RemoteTraceback(tb) + return exc + +# # Code run by worker processes # @@ -90,6 +114,7 @@ def worker(inqueue, outqueue, initializer=None, initargs=(), maxtasks=None): try: result = (True, func(*args, **kwds)) except Exception as e: + e = ExceptionWithTraceback(e, e.__traceback__) result = (False, e) try: put((job, i, result)) |