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
#!/usr/bin/env python | |
""" | |
http://stackoverflow.com/questions/20167735/python-multiprocessing-pipe-deadlock | |
""" | |
import logging | |
import multiprocessing as mp | |
def process(item): | |
print("adding ", item, "to done queue") | |
return item*100000 | |
def main(): | |
mp.log_to_stderr().setLevel(logging.DEBUG) | |
pool = mp.Pool(processes=4) | |
items = ("hi"+str(x) for x in range(10)) | |
for result in pool.imap_unordered(process, items, chunksize=2): | |
print(len(result)) | |
pool.close() | |
pool.join() | |
if __name__ == '__main__': | |
mp.freeze_support() | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment