[Twisted-Python] Re: Other ways to integrate foreign event loops?

glyph at divmod.com glyph at divmod.com
Thu Apr 3 17:41:45 EDT 2008

On 08:32 pm, nathan.stocks at gmail.com wrote:
>On Thu, Apr 3, 2008 at 1:35 PM, David Bolen <db3l.net at gmail.com> wrote:
>>  * During initialization, start reactor with reactor.startRunning()
>>  * At some periodic frequency, run reactor.iterate(0)
>>  * During termination, set up a reactor.callLater for reactor.stop, 
>>   then call reactor.mainLoop().  This was the cleanest way we found to
>>   permit all reactor finalization (events, final I/O, etc...).
>That's exactly what I was looking for, thanks!  I'll save this as the
>technique to try if all else fails and the time comes that I've got to
>deploy.  Hopefully we'll just be able to figure out what's going on
>and fix it before then.

Definitely for an "if all else fails" scenario, this should work well 
enough :).  But definitely reserve it for that.

For PyGame, there aren't too many other considerations which will 
practically cause problems, since you're spinning at full-throttle all 
the time and you are unlikely to want to integrate with too much other 
code.  (And if everything's written to just expect a normal, running 
reactor anyway, you can easily fix it later.)

For a regular GUI app though, waking up every 150ms or so can be more 
serious than the apparently negligible CPU usage it causes.  Try, for 
example, running your program under 
http://en.wikipedia.org/wiki/PowerTOP to see if this reactor integration 
mechanism is running down your laptop users' battery :).

(This message written from a laptop whose battery is no longer being 
devoured by Firefox's too-frequent wakeups...)

More information about the Twisted-Python mailing list