Created
March 5, 2016 00:04
-
-
Save wware/d92c1ff81ec021de608d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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