Skip to content

Instantly share code, notes, and snippets.

@wware
Created March 5, 2016 00:04
Show Gist options
  • Save wware/d92c1ff81ec021de608d to your computer and use it in GitHub Desktop.
Save wware/d92c1ff81ec021de608d to your computer and use it in GitHub Desktop.
import time
import multiprocessing
POOLSIZE = 4
N = 10
mgr = multiprocessing.Manager()
done = mgr.dict() # they don't implement sets. Thread-safe counter???
# this MUST be a globally defined funcion
def f(x):
global done_count
print x
time.sleep(1)
done[x] = 1
def go():
pool = multiprocessing.Pool(processes=POOLSIZE)
pool.map(f, range(N))
while len(done) < N:
time.sleep(0.1)
pool.terminate()
if __name__ == '__main__':
go()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment