[Twisted-Python] Twisted, wxPython & PyPubSub
gabriel.rossetti at arimaz.com
Wed Sep 9 03:12:23 EDT 2009
Ingénieur en Informatique
Av. du 24 Janvier 11
Ateliers de la Ville de Renens, Atelier 5
1020 Renens, Switzerland
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
>> 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.
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!
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.
More information about the Twisted-Python