[Twisted-Python] Perspective Broker and thread safe!

Ed Suominen general at eepatents.com
Fri Feb 6 21:54:59 EST 2009

This sort of thing is exactly what I wrote AsynCluster to do. See 

Best regards, Ed

B. B. wrote:
> 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!
> Brian
> ------------------------------------------------------------------------
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

More information about the Twisted-Python mailing list