Queue enhancement suggestion

Paul Rubin http
Tue Apr 17 01:22:47 EDT 2007


Antoon Pardon <apardon at forel.vub.ac.be> writes:
> The problem is this doesn't work well if you have multiple producers.
> One producer can be finished while the other is still putting values
> on the queue.

Right, you'd wait for all the producers to finish, then finish the queue:
   for p in producer_threads: p.join()
   q.finish()

> The solution I have been thinking on is the following.
> 
> Add an open and close operation. Only threads that have the queue
> open can access it. The open call should specify whether you
> want to read or write to the queue or both. When all writers
> have closed the queue and the queue is empty a q.get will
> raise an exception. This may be done by putting a sentinel
> on the queue when the last writer closed the queue.

That's an idea, but why would readers need to open the queue?



More information about the Python-list mailing list