Skip to content

Instantly share code, notes, and snippets.

@zed

zed/use-pool.py Secret

Created November 24, 2013 01:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zed/fc0ad934e903a5fac5ae to your computer and use it in GitHub Desktop.
Save zed/fc0ad934e903a5fac5ae to your computer and use it in GitHub Desktop.
#!/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