Skip to content

Instantly share code, notes, and snippets.

@QuynhVir
Last active January 9, 2019 06:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save QuynhVir/ccd4e315a37648b4df5b5dca1030fb9d to your computer and use it in GitHub Desktop.
Save QuynhVir/ccd4e315a37648b4df5b5dca1030fb9d to your computer and use it in GitHub Desktop.
multithreading and queue
from queue import Queue
from threading import Thread
def do_job(q):
while True:
print (q.get())
q.task_done()
q = Queue()
for i in range(3):
t = Thread(target=do_job, args=(q,))
t.setDaemon(True)
t.start()
for x in range(100):
q.put(x)
q.join()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment