Exception handling in concurrent.futures.Executor.map

前端 未结 3 1679
南方客
南方客 2021-01-04 21:46

From https://docs.python.org/3/library/concurrent.futures.html#concurrent.futures.Executor.map

If a func call raises an exception, then that exception

3条回答
  •  悲哀的现实
    2021-01-04 22:15

    The map method returns a generator which allows to iterate through the results once ready.

    Unfortunately, it is not possible to resume a generator after an exception occurs. From PEP 255.

    If an unhandled exception-- including, but not limited to, StopIteration --is raised by, or passes through, a generator function, then the exception is passed on to the caller in the usual way, and subsequent attempts to resume the generator function raise StopIteration. In other words, an unhandled exception terminates a generator's useful life.

    There are other libraries such as pebble which allow to continue the iteration after an error occurs. Check the examples in the documentation.

提交回复
热议问题