Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
from threading import Thread
from queue import Queue, Empty
from time import sleep
q = Queue()
def f():
while True:
try:
item = q.get_nowait()
except Empty:
return
else:
print(item**2)
sleep(5)
if __name__ == '__main__':
threads = [Thread(target=f) for _ in range(10)]
for i in range(100):
q.put(i)
for t in threads:
t.start()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question