[Twisted-Python] Two main loops, revisited
![](https://secure.gravatar.com/avatar/52e14c37ed1cbb215ce0e3560830d35a.jpg?s=120&d=mm&r=g)
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? Any suggestions would be much appreciated... -- Bernie Roehl Mail: broehl@gmail.com
![](https://secure.gravatar.com/avatar/2fe274d385cf2bb7f492d20a5631fc05.jpg?s=120&d=mm&r=g)
Am 28.11.2007, 04:56 Uhr, schrieb Bernie Roehl <broehl@gmail.com>:
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
![](https://secure.gravatar.com/avatar/d6328babd9f9a98ecc905e1ccac2495e.jpg?s=120&d=mm&r=g)
On 03:56 am, broehl@gmail.com wrote:
As you've explained it here, that should be impossible under any circumstances. Can you provide a minimal, runnable example that demonstrates what you mean by "losing messages"? Given Twisted's pretty awesome track record in this regard, I'd say that it's most likely that your networking code is not dealing with different levels of latency very well - a common error is treating a chunk sent to dataReceived as a single message (it isn't, it's a randomly-sized chunk of data received from the network).
Most likely an event handler registered on a network socket is doing something that blocks or takes a long time to complete. That isn't Twisted, that's your application. Tools like 'strace' can help you figure out what's going on.
Twisted was originally designed for MMORPGs; its very first commercial applications were integrated with a real-time 3D engine (a very distant cousin of which, I believe, now powers the game Tabula Rasa). I had no issues with it then, and I don't believe anyone who has used it more recently has had problems like the ones you're describing.
![](https://secure.gravatar.com/avatar/2fe274d385cf2bb7f492d20a5631fc05.jpg?s=120&d=mm&r=g)
Am 28.11.2007, 04:56 Uhr, schrieb Bernie Roehl <broehl@gmail.com>:
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
![](https://secure.gravatar.com/avatar/d6328babd9f9a98ecc905e1ccac2495e.jpg?s=120&d=mm&r=g)
On 03:56 am, broehl@gmail.com wrote:
As you've explained it here, that should be impossible under any circumstances. Can you provide a minimal, runnable example that demonstrates what you mean by "losing messages"? Given Twisted's pretty awesome track record in this regard, I'd say that it's most likely that your networking code is not dealing with different levels of latency very well - a common error is treating a chunk sent to dataReceived as a single message (it isn't, it's a randomly-sized chunk of data received from the network).
Most likely an event handler registered on a network socket is doing something that blocks or takes a long time to complete. That isn't Twisted, that's your application. Tools like 'strace' can help you figure out what's going on.
Twisted was originally designed for MMORPGs; its very first commercial applications were integrated with a real-time 3D engine (a very distant cousin of which, I believe, now powers the game Tabula Rasa). I had no issues with it then, and I don't believe anyone who has used it more recently has had problems like the ones you're describing.
participants (3)
-
Bernie Roehl
-
glyph@divmod.com
-
Nitro