Last active
January 9, 2019 06:22
-
-
Save QuynhVir/ccd4e315a37648b4df5b5dca1030fb9d to your computer and use it in GitHub Desktop.
multithreading and queue
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
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