Created
October 14, 2010 16:35
-
-
Save aljungberg/626518 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Fix keyboard interrupts when using multiprocessing.pool.imap(). | |
# Usage: | |
# import fix_multiprocessing.py | |
from multiprocessing.pool import IMapIterator | |
def wrapper(func): | |
def wrap(self, timeout=None): | |
# Note: the timeout of 1 googol seconds introduces a rather subtle | |
# bug for Python scripts intended to run many times the age of the universe. | |
return func(self, timeout=timeout if timeout is not None else 1e100) | |
return wrap | |
IMapIterator.next = wrapper(IMapIterator.next) |
FYI, I have been using this code for a while in https://github.com/nexB/scancode-toolkit/blob/4ec7a92ac21bf050a872b5dc07ce22baefcfb41d/src/scancode/pool.py
Thank you ++
Hah, that's awesome! Thanks for the heads up.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks!