Not fully understanding the role of Queue.task_done()

Aahz aahz at pythoncraft.com
Sun Sep 7 16:18:03 CEST 2008


In article <mailman.504.1220561513.3487.python-list at python.org>,
Fredrik Lundh  <fredrik at pythonware.com> wrote:
>Martin DeMello wrote:
>>
>> In the interests of not hammering the db unnecessarily, I'm
>> considering the following
>> 1. A series of independent "monitor" threads that collect information
>> over TCP from the cluster of machines, and write it to a queue
>> 2. A "logger" thread that empties the queue every second or so and
>> inserts the collected information to the db via a single insert
>> statement
>
>why are you using a queue for this case, btw?  why not just use a plain list
>
>     L = []
>     lock = threading.Lock()
>
>and add stuff using append in the monitor threads
>
>     with lock:
>         L.append(item)

Because using a queue requires less thinking.  I certainly would use a
queue in this case instead of rolling my own.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"Argue for your limitations, and sure enough they're yours."  --Richard Bach



More information about the Python-list mailing list