On 06/13/2012 11:00 AM, Dave Cook wrote: > Originally, I was trying to send formatted > tracebacks back to the main process on a queue. You can still do that:
import multiprocessing import sys def queueErrors(q): def decorator(func): def wrapped(*args, **kwargs): try: func() except: q.put((multiprocessing.current_process().name, repr(sys.exc_info()))) return wrapped return decorator q = multiprocessing.Queue() @queueErrors(q) def target(): raise ValueError() if __name__ == '__main__': p = multiprocessing.Process(target=target) p.start() p.join() # try it here in main while True: pname,exc = q.get() print('Caught error in process %r: %s' % (pname, exc)) It gets somewhat harder when you also want to catch termination of threads, but you can just queue a special message. - Philipp
signature.asc
Description: OpenPGP digital signature
-- http://mail.python.org/mailman/listinfo/python-list