Last active
August 29, 2015 14:27
-
-
Save lucastheis/919326449492b5106313 to your computer and use it in GitHub Desktop.
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
from multiprocessing import Process, Pool, Queue | |
def f(q0): | |
for i in range(100): | |
q0.put(i) | |
def g(q0, q1): | |
while True: | |
q1.put(q0.get()) | |
q0 = Queue(maxsize=10) | |
q1 = Queue() | |
p0 = Process(target=f, args=(q0,)) | |
p1 = Pool(4, initializer=g, initargs=(q0, q1)) | |
p0.start() | |
p0.join() | |
while q0.qsize() > 0: | |
pass | |
p1.terminate() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment