hi all, I have a simple program that uses multiple threads to carry out
some work. Every threads share the same queue.Queue() (that is
synchronized) in order to get some data and then carry out the work.
Suppose I have something like:
q = queue.Queue()
for x in range(100):
q.put(x)
then I have:
lock = threading.Lock()
d = {}
threads = [Thread(target=do_work, args=(q, lock, d)) for _ in range(5)]
every thread thakes an item in the queue (using .get()) and compute some
expensive work. Then updates the dictionary using the queue item as a key
and the result obtained as the value (using the lock before and after the
dict update).
Now, I would like to know the activity done (e.g. every two seconds) so I
create another thread that checks the queue size (using .qsize()). Have
you any suggestion to improve the code?
--
http://mail.python.org/mailman/listinfo/python-list