[Twisted-Python] Multiple main loops

glyph at divmod.com glyph at divmod.com
Tue May 2 16:38:56 MDT 2006


On Tue, 02 May 2006 12:00:53 -0300, David Pratt <fairwinds at eastlink.ca> wrote:
>Hi. I am hoping you can clarify for me whether it is possible to run 
>multiple independent main loops in Twisted. It is my understanding that this 
>would mean separate independent reactors.

Yep.  This is not currently possible.  Most importantly there are no tests for it, so we would have no idea if it worked.  Writing tests for race conditions is notoriously hard.

>Googling, I found this patch but after looking into the repository, it was 
>never committed. I would appreciate any comments on the patch or attempts 
>people have made on the integration of a second twisted loop.

This patch was deliberately left uncommitted.  It definitely reverses an optimization that was demonstrated to improve performance on the critical path; it only maybe makes it possible to initialize multiple reactors.  If you want to write a comprehensive set of unit tests for multiple reactors, we might consider doing something like this, otherwise the reactor will be left in its current state in order to discourage people from attempting to start multiple reactors concurrently.

>At the present time I am using twisted with wxpython with wxpython as main 
>loop and also running a selectreactor instance. Here there are two separate 
>loops, interoperating and operating independently, however they are not both 
>twisted loops.

wxpython is buggy and has terrible event-loop support.  Consider using PyGTK instead.  If you really must use wx, there are a variety of mostly-working ways to integrate the mainloop with Twisted without resorting to multiple reactors.




More information about the Twisted-Python mailing list