Multi thread reading a file

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Thu Jul 2 06:10:17 EDT 2009


En Wed, 01 Jul 2009 12:49:31 -0300, Scott David Daniels  
<Scott.Daniels at acm.org> escribió:

> Gabriel Genellina wrote:
>> ...
>> def convert(in_queue, out_queue):
>>   while True:
>>     row = in_queue.get()
>>     if row is None: break
>>     # ... convert row
>>     out_queue.put(converted_line)
>
> These loops work well with the two-argument version of iter,
> which is easy to forget, but quite useful to have in your bag
> of tricks:
>
>      def convert(in_queue, out_queue):
>          for row in iter(in_queue.get, None):
>              # ... convert row
>              out_queue.put(converted_line)

Yep, I always forget about that variant of iter() -- very handy!

-- 
Gabriel Genellina




More information about the Python-list mailing list