[Twisted-Python] Two main loops, revisited

Nitro nitro at dr-code.org
Tue Nov 27 21:12:37 MST 2007


Am 28.11.2007, 04:56 Uhr, schrieb Bernie Roehl <broehl at gmail.com>:

> Hi everyone
>
> So, I've been trying the suggestion that was put forward when I asked my
> earlier question about having two main loops in my game (one for the
> rendering engine, one for Twisted).
>
> Basically, what I'm doing is this:
>
> def renderFrame():
>     ogreLock.acquire()
>     ogre.WindowEventUtilities.messagePump()
>     root.renderOneFrame()
>     ogreLock.release()
>
> renderTask = task.LoopingCall(renderFrame)
> renderTask.start(0.01, False)
> reactor.run()
>
> I'm using the Python implementation of the Project Darkstar client,  
> which is
> built around Twisted.
>
> Unfortunately, I'm running into two problems.
>
> The first is that I appear to be losing messages, which makes me wonder  
> if
> Twisted isn't getting enough cycles and is somehow missing incoming data.
>
> The second is that my application hangs randomly.  When I call  
> renderFrame()
> in a simple loop (no Twisted), everything is rock-solid.
>
> Has anyone done anything like this before (realitime 3D application with
> Twisted), or am I breaking new ground here?

No new ground here, it works with my 3d engine.

> Any suggestions would be much appreciated...

You could try to increase 0.01 to something like 0.5 and see if this helps  
the losing messages. I am not really sure how the default twisted reactor  
(i guess on win it's threadedselect) works, but what might be happening is  
that twisted receives some incoming data during your rendering and does  
some kind of processing or whatever. Maybe this is causing random trouble?

-Matthias




More information about the Twisted-Python mailing list