[Twisted-Python] Perspective Broker and thread safe!

B. B. thebbzoo at gmail.com
Fri Feb 6 11:30:19 EST 2009

Hello, I am relative new to twisted, though I have manage to make a simple
client server solution ( using perspective broker ) that I am now try to
refactor a little.

The solution is now something like :

Using perspective broker, clients connects to the server ( setting up a
remote reference to each other ).
Via a PB call, each client can request the server do some processing. The
result of  the processing is distributed to each connected client - and the
client asking for the request gets a simple status report!

This solution works quite well, the only bottleneck is that all the
"thread-safe" processing on the server is done in the mainloop of the server
reactor. I want to do concurrent processing on the server!

The function doing the processing on the server, also distribute the result
to all the connected clients, and returns the result to the klient asking
for the request.

My question is :
If I just "defer" that function "toThread" ( like  threads.deferToThread(
myServerProcessingFunction ) ). Do I have potential problems, when several
threads try to distribute its result to the connecting clients???

If I have a problem:
Can I make a quick fix as follows:  Within each thread ( started with the
threads.deferToThread function ), I do the distributing to the clients by
using the "reactor.callFromThread"
( like reactor.callFromThread( distributeToAllClient , myResult ) where the
function distributeToAllClient are using the remoteReference for each client
to send the "myResult" )

Or is the only solution, to let the myServerProcessingFunction returns the
"myResult" to be distributed to all connected clients, and do the
distribution in the reactor mainthread???

Thank you!

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20090206/5fd2a31a/attachment.htm 

More information about the Twisted-Python mailing list