Skip to content

Instantly share code, notes, and snippets.

@dinob0t
Created March 22, 2016 16:28
Show Gist options
  • Save dinob0t/7c669f17cc597affdec8 to your computer and use it in GitHub Desktop.
Save dinob0t/7c669f17cc597affdec8 to your computer and use it in GitHub Desktop.
import threading
from Queue import Queue
NUMBER_THREADS = 2
work = range(1,11)
q = Queue()
def queue_work():
while True:
number = q.get()
if not number:
break
print number
q.task_done()
threads = []
for i in range(NUMBER_THREADS):
worker = threading.Thread(target=queue_work)
threads.append(worker)
worker.start()
for i in work:
q.put(i)
q.join()
for i in range(NUMBER_THREADS):
q.put(None)
for t in threads:
t.join()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment