[Twisted-Python] Two main loops

Bernie Roehl broehl at gmail.com
Sun Nov 11 09:51:33 EST 2007


Did you find that passing zero as the first parameter to callLater
cause it to be called often enough?  I really want to make sure the
rendering is happening as quickly as possible.


So does callLater(0, DoOneLoopIteration) call

On Nov 11, 2007 9:20 AM, Nitro <nitro at dr-code.org> wrote:
> Am 11.11.2007, 15:03 Uhr, schrieb Bernie Roehl <broehl at gmail.com>:
>
>
> > I've got a 3D game that I've implemented in Python using an existing
> > game engine.  The engine "owns" the main loop, i.e. I call
> > engine.run() and it makes callbacks to my application on every frame
> > (and other game event).
> >
> > 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?
> >
> > My first though is to call reactor.run() in a separate thread, but of
> > course that adds additional complexity in terms of synchronization.
> >
> > I notice the docs mention reactor.iterate(), which appears to be
> > designed for exactly what I'm doing.  However, it's not clear how to
> > use it, and the method appears to be deprecated.
> >
> > Any suggestions are appreciated...
>
> 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()
>
> There are other possibilities like
>
> import twisted.internet.task
> scheduleUpdate = twisted.internet.task.LoopingCall(DoOneLoopIteration)
> scheduleUpdate.start(0.01, False)   # 100 Hz
>
> They all have in common that twisted is driving the main loop and the 3d
> part of the app only executes the inner part of it's main loop. I tried
> the opposite way before (3d part of the app driving main loop, twisted
> being run with iterate()) but this wasn't really usable.
>
> -Matthias
>
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>



-- 
   Bernie Roehl
   Mail: broehl at gmail.com




More information about the Twisted-Python mailing list