[Twisted-Python] Other ways to integrate foreign event loops?
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
> if w.has_exit and reactor.running:
> 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:
> 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)
> 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.
More information about the Twisted-Python