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

Nathan nathan.stocks at gmail.com
Mon Mar 31 18:45:04 EDT 2008

Is there a way to do the opposite of task.coiterate?  I'm using pyglet
for my UI, which was working great until I upgraded from pyglet 1.0 to
1.1.  Now for some reason, the pyglet performance tanked.  Since I'm
only using twisted to send AMP messages very rarely (on the order of
one every few seconds), it seems like I could try to work around the
problem by giving pyglet back control of the main loop and
occasionally giving twisted some time to breath (occasionally like
every 50ms or something).  Can that be done?

Here's what I'm doing _now_ that technically works, but pyglet 1.1 is
really choking on:

> class MyWindow(pyglet.window.Window):
>  def run(self):
>     while not self.has_exit:
>        do_some_stuff_like_dispatching_updating_and_drawing()
>        yield 1
> my_window = MyWindow()
> task.coiterate(my_window.run())
> reactor.run()

By the way, the preferred method for the runloop on pyglet 1.1 is to
use a builtin one like so:

> window = pyglet.window.Window()
> @window.event
> def on_draw():
>    window.clear()
>    do_drawing_stuff()
> pyglet.app.run()

So if twisted can stand giving up it's run loop, I could periodically
call it from that "on_draw()" method.

~ Nathan

More information about the Twisted-Python mailing list