def map(self, func, iterable, chunksize=None):
"""
Equivalent of `map()` built-in, without swallowing
`KeyboardInterrupt`.
:param func:
The function to apply to the items.
:param iterable:
An iterable of items that will have `func` applied to them.
"""
# The key magic is that we must call r.get() with a timeout, because
# a Condition.wait() without a timeout swallows KeyboardInterrupts.
r = self.map_async(func, iterable, chunksize)
while True:
try:
return r.get(self.wait_timeout)
except multiprocessing.TimeoutError:
pass
except KeyboardInterrupt:
self.terminate()
self.join()
raise
评论列表
文章目录