[Twisted-Python] Twisted and python-ogre

Thomas Boucher thomas.boucher at student.ecp.fr
Fri Feb 15 07:01:21 MST 2008


Jean-Paul Calderone a écrit :
> Chris Armstrong's response to the post you refer to is accurate.  Twisted
> APIs are not threadsafe.  In order to call them from a thread other than
> the one in which the reactor is running, it is absolutely required that you
> use reactor.callFromThread.  This is quite simple.  Instead of:
> 
>    proto.sendLine("line")
> 
> Simple do:
> 
>    reactor.callFromThread(proto.sendLine, "line")
> 
> You will have to do this for every call you make to a Twisted API (except
> for reactor.callFromThread, of course ;).

I have just tried this method, and it perfectly works.
The twisted reactor is run in another thread and the calls to Twisted 
are managed by the callFromThread method. The main advantage I see to it 
(excepting the fact that it works) is that it does not require changes 
in the way the graphic rendering is done : you do not care about how 
python-ogre runs to code the twisted part.

> The best solution would be to really integrate the two loops.  I don't know
> the details of OGRE though, so I can't tell you specifically how to do 
> this.
> It is tightly dependent on the details of the loops being integrated.

What I can't see for the moment is how much better it would be to do 
like the other ways delivered in the discussion thread (by Werner, 
Bernie an Stefan). These ways consist in running Twisted first and in 
letting it manage python-ogre (by doing the rendering frame by frame 
with coiteration, or loopingcalls).
Is this better than doing separate threads ?

> Because most other event loops are very bad at managing events. :)  If you
> want reasonable network performance, you need a good network event loop to
> be in control.

Don't you think using basic sockets (easy to code in Python) to make the 
network connection from a client to a server is more efficient 
(considering the time spent to do it or the complexity of the code) and 
more easy to keep in a project ?

I suppose the connexion is better managed with Twisted with a lot of 
control (and moreover there are huge libs) but to what extend ?


Anyway, thanks for all the suggestions already given by everybody.

Cheers

-- 
Thomas Boucher




More information about the Twisted-Python mailing list