Created
August 9, 2014 20:46
-
-
Save talitore/f7d7c7573027efcd69b2 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
import threading | |
from queue import Queue | |
def worker(): | |
while True: | |
item = q.get() | |
do_work(item) # Do shit here | |
q.task_done() | |
q = Queue() | |
for i in range(num_worker_threads): | |
t = Thread(target=worker) | |
t.daemon = True | |
t.start() | |
for item in source(): | |
q.put(item) | |
q.join() # block until all tasks are done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment