# HG changeset patch # User Andrey Vlasovskikh # Date 1270573947 -14400 # Node ID 0e3b2d6a627b4f753daecb57127f9c9574386cac # Parent 0545f6ad6c37c8b4286b2de9012cca4f016a155f Issue #8296: Catch and report all exceptions in multiprocessing.Pool workers diff -r 0545f6ad6c37 multiprocessing/pool.py --- a/multiprocessing/pool.py Tue Apr 06 21:12:27 2010 +0400 +++ b/multiprocessing/pool.py Tue Apr 06 22:05:25 2010 +0400 @@ -46,6 +46,7 @@ assert maxtasks is None or (type(maxtasks) == int and maxtasks > 0) put = outqueue.put get = inqueue.get + if hasattr(inqueue, '_writer'): inqueue._writer.close() outqueue._reader.close() @@ -53,25 +54,27 @@ if initializer is not None: initializer(*initargs) + job = i = 0 completed = 0 + while maxtasks is None or (maxtasks and completed < maxtasks): try: - task = get() - except (EOFError, IOError): - debug('worker got EOFError or IOError -- exiting') - break + try: + task = get() + except (EOFError, IOError): + debug('worker got EOFError or IOError -- exiting') + break - if task is None: - debug('worker got sentinel -- exiting') - break + if task is None: + debug('worker got sentinel -- exiting') + break - job, i, func, args, kwds = task - try: - result = (True, func(*args, **kwds)) - except Exception, e: - result = (False, e) - put((job, i, result)) - completed += 1 + job, i, func, args, kwds = task + put((job, i, (True, func(*args, **kwds)))) + except BaseException, e: + put((job, i, (False, e))) + finally: + completed += 1 debug('worker exiting after %d tasks' % completed) #