[Twisted-Python] daemon thread support

Andrew Bennetts andrew-twisted at puzzling.org
Tue Dec 2 21:05:08 EST 2003


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)))

;)

-Andrew.





More information about the Twisted-Python mailing list