[Twisted-Python] Two main loops

Itamar Shtull-Trauring itamar at itamarst.org
Sun Nov 11 10:00:21 EST 2007

On Sun, 2007-11-11 at 15:20 +0100, Nitro wrote:
> > Now I'm adding networking, and I'd like to use Twisted.  However,
> > Twisted uses the same approach as the game engine -- I call
> > reactor.run() and it makes callbacks to my application.
> >
> > So, how do I integrate the two?

> I am using twisted with our home-brewn 3d engine and I do it like this:
> def DoOneLoopIteration():
>      engine.RunSingleIteration()
>      reactor.callLater(0, DoOneLoopIteration)
> reactor.callLater(0, DoOneLoopIteration)
> reactor.run()

Or, if your game event loop supports registering sockets, you could
build your own reactor; that's e.g. how twisted.internet.glib2reactor
works, using glib's event loop and socket notification mechanism.

More information about the Twisted-Python mailing list