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

Nathan nathan.stocks at gmail.com
Tue Apr 1 18:00:39 EDT 2008

On Mon, Mar 31, 2008 at 10:18 PM, Drew Smathers <drew.smathers at gmail.com> wrote:
>  Yeah, I've experienced some performance issues with pyglet's
>  app.runtime (maybe Linux-specific or something).  Given the time, I'll
>  submit a meaningful bug report concerning this.  Regarding integration
>  with Twisted, though, I think the best thing to do (for now) is to
>  just ignore pyglet.app.runtime and write a pump function, roughly:
>  def pump():
>     dt = clock.tick(True) # polling tick
>     w.clear()
>     w.dispatch_events()
>     ...
>     w.flip()
>     if w.has_exit and reactor.running:
>         reactor.stop()
>  Be sure to call clock.tick(True) - since clock.tick will otherwise
>  block.  The next thing to do is customize clock where appropriate -
>  that is, to used Twisted's scheduling functions.  Coincidentally, I
>  did this about 45 minutes ago for a project I'm working on:
>  http://hg.enterthefoo.com/roboto/file/db931f29b98e/roboto/clock.py
>  Beware - the above is half-baked and written under the influence of
>  Hobgoblin Dark English Ale.
>  Finally, you need schedule the pump function.  To do it as fast as possible:
>     from twisted.internet import task
>     gameLoop = task.LoopingCall(pump)
>     gameLoop.start(0., True)
>     reactor.run()
>  Or with a set framerate:
>    ...
>    gameLoop.start(1/60., True)

Thanks for the great advice.  I implemented it all and it runs, but
unfortunately there was no noticeable change (for better or worse) to
pyglet's performance.  I'm currently working on setting up a
stripped-down twisted+pyglet example that reproduces the problem.
I'll post it when I get it up and running.

~ Nathan

More information about the Twisted-Python mailing list