[Twisted-Python] Twisted, wxPython & PyPubSub

Gabriel Rossetti gabriel.rossetti at arimaz.com
Wed Sep 9 03:12:23 EDT 2009

Arimaz SA
Ingénieur en Informatique
Av. du 24 Janvier 11
Ateliers de la Ville de Renens, Atelier 5
1020 Renens, Switzerland
Mob: +41-(0)79-539-0069
Tel: +41-(0)21-566-7343

exarkun at twistedmatrix.com wrote:
> On 02:21 pm, gabriel.rossetti at arimaz.com wrote:
>> Hello everyone,
>> I am using wx with twisted and pubsub (not the on in wx but the
>> independent one) to notify each one of what is going on. I was 
>> wondering
>> if I should use reactor.callFromThread to call publisher.sendMessage or
>> not? I haven't been doing that until now but I wondered if it was 
>> better to.
> Use reactor.callFromThread if you have code running in a non-reactor 
> thread and you want it to initiate some action in the reactor thread.
> So, if publisher.sendMessage is using Twisted APIs or otherwise requires 
> that it be run only in the reactor thread, and you need to use it from a 
> non-reactor thread, then use reactor.callFromThread.  Otherwise, don't.
> Jean-Paul

Would you consider the wxreactor like a non-reactor thread? I haven't 
checked out the code behind PyPubSub, but it's basically the 
Observer-Pattern so when I call publisher.sendMessage(...) it iterates 
the "subscribers" (observers) and calls the functions they associated w/ 
the subscription. Those functions are both in the twisted code and the 
wx code. The Twisted code sends messages nd the wx code brings-up/hides 
dialogs or frames. In the wxdemo it does :

# look, we can use twisted calls!
reactor.callLater(2, self.twoSecondsPassed)

but doesn't use reactor.callFromThread, but unless I'm wrong 
reactor.callLater does the same thing but deferred in time. I often see 
reactor.callLater(0, myFunc) being used.

Thank you,

More information about the Twisted-Python mailing list