I am trying to get hold of a traceback object from a multiprocessing.Process. Unfortunately passing the exception info through a pipe does not work because traceback objects
The same solutions as @Syrtis Major and @interfect but, tested with Python 3.6:
import sys
import traceback
import functools
def catch_remote_exceptions(wrapped_function):
""" https://stackoverflow.com/questions/6126007/python-getting-a-traceback """
@functools.wraps(wrapped_function)
def new_function(*args, **kwargs):
try:
return wrapped_function(*args, **kwargs)
except:
raise Exception( "".join(traceback.format_exception(*sys.exc_info())) )
return new_function
Usage:
class ProcessLocker(object):
@catch_remote_exceptions
def __init__(self):
super().__init__()
@catch_remote_exceptions
def create_process_locks(self, total_processes):
self.process_locks = []
# ...