New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
multiprocessing exceptions with useful traceback #62036
Comments
In pool.py, the worker function reads as follows: http://svn.python.org/view/python/trunk/Lib/multiprocessing/pool.py?view=markup If an exception is raised in the function you sent to the pool, the exception you get has "raise self._value" as the last line; which is correct but useless for debugging. mp_exception_bug.py reproduces this error. This is the output: """
Traceback (most recent call last):
File "mp_exception_bug.py", line 8, in <module>
print p.map(f, [1,2,3])
File "/usr/lib/python2.7/multiprocessing/pool.py", line 227, in map
return self.map_async(func, iterable, chunksize).get()
File "/usr/lib/python2.7/multiprocessing/pool.py", line 528, in get
raise self._value
NameError: global name 'y' is not defined
""" As you can imagine, "NameError: global name 'y' is not defined" is not enough in complex projects. If we apply some changes to the pool.py we could get something similar to this: """
Traceback (most recent call last):
File "/usr/lib/python2.7/multiprocessing/pool.py", line 98, in worker
result = (True, func(*args, **kwds))
File "/usr/lib/python2.7/multiprocessing/pool.py", line 67, in mapstar
return map(*args)
File "mp_exception_bug.py", line 4, in f
return x*y
NameError: global name 'y' is not defined
Traceback (most recent call last):
File "mp_exception_bug.py", line 8, in <module>
print p.map(f, [1,2,3])
File "/usr/lib/python2.7/multiprocessing/pool.py", line 231, in map
return self.map_async(func, iterable, chunksize).get()
File "/usr/lib/python2.7/multiprocessing/pool.py", line 535, in get
raise self._value[0]
NameError: global name 'y' is not defined
""" The patch is simple but ugly: """
Note that I tried to replace the "raise self._value[0]" with a raise with three parameters, being the last one the traceback we get using "exc_info = sys.exc_info()" but sadly it is not possible to pickle tracebacks. I understand that printing is not the best thing to do here, but I wanted to get this discussion started and come to a real solution. Thanks |
(FYI, cpython source is no longer maintained in svn.python.org; the browser link you provided is out-of-date. Current source for the 2.7 branch can be viewed here: http://hg.python.org/cpython/file/2.7/) |
Duplicate of bpo-13831. |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: