[Twisted-Python] Advice on Writing a Custom Twisted Reactor

Andrew Francis andrewfr_ice at yahoo.com
Wed Jan 10 15:44:16 MST 2007

Hello Colleagues:

I am a first time poster...

For the past few months I have been experimenting with
using Stackless Python with Twisted. I still consider
myself very much a Twisted newbie. Currently my
problems involve deferreds.

>From doing online searches, I have run across
customized reactors for Twisted. Consequently I am
looking at the custom reactors that come with Twisted.
Like Stackless, many GUIs have a hard time working
with Twisted which blocks. Based on the
ThreadedSelectReactor, most of the reactors are for
GUIs. The general idea is that custom reactor's event
loop calls Twisted in its own thread. This approach
seems like it would work for Stackless and provide a
decent general solution. However there are a few
places where I am not quite clear.

Most of my Stackless programmes have the following
form (think of this as a MainLoop):


set up stuff

while (stackless.getruncount() > 1):


Since it seems my custom reactor has to call Twisted
as often as possible. I would wrap
stackless.schedule() (since this is often called):

    __hook__() # some method that would call Twisted

Where I start to get a bit confused is:

1) In the Custom reactor.run() method, do I call 
self.__hook__() in the interleave() method? Is there
anything more I have to do in the run() method? Can I
avoid signal handler issues by passing False to
Twisted's reactor.run() ?

2) From my Stackless code, do I have to use
self.callFromThread() to call Twisted methods that
involve deferreds?

Again, any advice would be welcomed.


Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 

More information about the Twisted-Python mailing list