Python 2 examples taken while learning SPSE
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

26 lines
509 B

#!/usr/bin/python
# -*- coding: utf-8 -*-
# Thanks: https://www.troyfawkes.com/learn-python-multithreading-queues-basics/
from Queue import Queue
from threading import Thread
def do_work(q):
while True:
print q.get()
q.task_done()
q = Queue(maxsize=0)
num_threads = 5
for i in range(num_threads):
worker = Thread(target=do_work, args=(q,))
worker.setDaemon(True)
worker.start()
for a in range (10):
for b in range(50):
q.put(a+b*50)
q.join()
print "Work " + str(y) + ": done."