[Twisted-Python] Twisted, wxPython & PyPubSub

exarkun at twistedmatrix.com exarkun at twistedmatrix.com
Thu Sep 10 10:03:27 EDT 2009

On 01:47 pm, gabriel.rossetti at arimaz.com wrote:
>exarkun at twistedmatrix.com wrote:
>>On 9 Sep, 07:12 am, gabriel.rossetti at arimaz.com wrote:
>>>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 
>>>>>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 
>>>>So, if publisher.sendMessage is using Twisted APIs or otherwise
>>>>that it be run only in the reactor thread, and you need to use it 
>>>>non-reactor thread, then use reactor.callFromThread.  Otherwise,
>>>Would you consider the wxreactor like a non-reactor thread?
>>I'm not sure what you mean.  The "reactor thread" is the thread that
>>"reactor.run()" is called in.  Even if you're using wxreactor.
>>>I haven't
>>>checked out the code behind PyPubSub, but it's basically the
>>>Observer-Pattern so when I call publisher.sendMessage(...) it 
>>>the "subscribers" (observers) and calls the functions they associated
>>>the subscription. Those functions are both in the twisted code and 
>>>wx code. The Twisted code sends messages nd the wx code brings- 
>>>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 
>>>reactor.callLater(0, myFunc) being used.
>>The wx demo doesn't do anything with threads, so it doesn't need to 
>>callFromThread.  So, if you're only doing things like what the wx demo
>>does, you probably don't need callFromThread either.
>>callLater doesn't do the same thing as callFromThread.  There might be
>>some vague similarities (really the only one is that neither one calls
>>the function you pass it right away), but they're for very different
>Ok, well, from looking into the twisted source, it looks like the wx
>main loop is run in a seperate thread

That's an implementation detail.  You've also misinterpreted it 
slightly.  The wx main loop is run in the same thread reactor.run() is 
called in.  The other thread is used for other things.


More information about the Twisted-Python mailing list