Skip to content

Instantly share code, notes, and snippets.

@talitore
Created August 9, 2014 20:46
Show Gist options
  • Save talitore/f7d7c7573027efcd69b2 to your computer and use it in GitHub Desktop.
Save talitore/f7d7c7573027efcd69b2 to your computer and use it in GitHub Desktop.
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