[Twisted-Python] daemon thread support

Bob Ippolito bob at redivi.com
Tue Dec 2 21:46:20 EST 2003


On Dec 2, 2003, at 9:15 PM, Jp Calderone wrote:

> On Wed, Dec 03, 2003 at 01:05:08PM +1100, Andrew Bennetts wrote:
>> On Wed, Dec 03, 2003 at 11:26:40AM +1100, Andrew Bennetts wrote:
>>>
>>> You could change it to:
>>>
>>>     while 1:
>>>         nextTask = queue.get()  # queue is a Queue.Queue instance
>>>         if nextTask is None:
>>>             break
>>>         process(nextTask)
>>
>> Or as exarkun pointed out on IRC:
>>
>> <exarkun> reactor.callInThread(itertools.imap, process, 
>> iter(queue.get, None))
>> <exarkun> Where else can you find a generalized one line thread-worker
>>           implementation?
>>
>> Although you don't need Twisted for that, you could probably do:
>>
>>     threading.Thread(target=itertools.imap, args=(process, 
>> iter(queue.get, None)))
>>
>
>   This makes using threads far, far too easy.  Luckily for everyone, 
> on a
> second reading, I don't think these will work.  imap needs something to
> iterate the object it returns.  Both of the above solutions will simply
> create an itertools.imap object and then do nothing with it :)

What about list as the function, and itertools.imap as the argument to 
that function?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2357 bytes
Desc: not available
Url : http://twistedmatrix.com/pipermail/twisted-python/attachments/20031202/73f6abd0/attachment.bin 


More information about the Twisted-Python mailing list