[Twisted-Python] daemon thread support
Jp Calderone
exarkun at intarweb.us
Tue Dec 2 21:15:01 EST 2003
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 :)
Jp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://twistedmatrix.com/pipermail/twisted-python/attachments/20031202/9a4b757f/attachment.pgp
More information about the Twisted-Python
mailing list