Skip to content

Instantly share code, notes, and snippets.

@KushalVenkatesh
Forked from lamarmarshall/multimanager.py
Created January 21, 2018 03:47
Show Gist options
  • Save KushalVenkatesh/6a56c72cb610cc6708d8df30f425e312 to your computer and use it in GitHub Desktop.
Save KushalVenkatesh/6a56c72cb610cc6708d8df30f425e312 to your computer and use it in GitHub Desktop.
python multiprocessing manager / queue
import multiprocessing
def worker(dict, key, item):
dict[key] = item
if __name__ == '__main__':
mgr = multiprocessing.Manager()
dictionary = mgr.dict()
jobs = [multiprocessing.Process(target=worker, args=(dictionary, i, i*2)) \
for i in range(10)]
for j in jobs:
j.start()
for j in jobs:
j.join()
print(dictionary)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment