Skip to content

Instantly share code, notes, and snippets.

@sneeu
Created January 4, 2010 17:53
Show Gist options
  • Save sneeu/268687 to your computer and use it in GitHub Desktop.
Save sneeu/268687 to your computer and use it in GitHub Desktop.
import Queue
import threading
def do_work(*args):
# Do something with args
pass
number_of_workers = 20
work_queue = Queue.Queue()
def worker():
while True:
item = work_queue.get()
do_work(*item)
work_queue.task_done()
for __ in range(number_of_workers):
t = threading.Thread(target=worker)
t.setDaemon(True)
t.start()
for item in work_source():
work_queue.put(item)
work_queue.join()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment