[Twisted-Python] reactor.stop() and thread and wxPython problem

Gabriel Rossetti gabriel.rossetti at arimaz.com
Fri Jan 16 07:45:12 EST 2009

Reza Lotun wrote:
> Hi Gabriel,
> I don't quite understand your question. Do you mean to say that you
> have written some code with wx and Twisted in an integrated event
> loop, and are doing something like reactor.callInThread(someCall), and
> when you call reactor.stop the app doesn't exit? AFAIK, any thread
> spawning goes through Twisted's internal thread pool and thread
> joining should be handled by reactor.stop - I suppose it depends on
> what those threads are doing.

Almost :-) I have 2 programs, one is Twisted + wx using the integrated 
event loop, as described in the Twisted documentation. This program has 
no threads, but I use reactor.callFromThread sometimes from the wx part.

The other program is Twisted with no wx but it uses threads 

They both have trouble sometimes closing when reactor.stop() is called, 
not always though.

> Based on my experience with wx and Twisted, I found the following
> works quite well:
> * Have the reactor run in a seperate thread from wx (making sure to
> use reactor.run(installSignalHandlers=False))
> * Spawn threads from wx->Twisted in the proper way: use
> reactor.callFromThread(reactor.callInThread(someCall))

Hmmm, I'll give that a try later on, does it work better than the 
official way of doing it? Has anyone else tried this?

> Hope this helped,
> Reza
Thanks Reza
> On Fri, Jan 16, 2009 at 7:37 AM, Gabriel Rossetti
> <gabriel.rossetti at arimaz.com> wrote:
>> Hello everyone,
>> I have written some code using Twisted that spawns threads and another using
>> wxPython integration. For some reason when reactor.stop() is called they
>> don't always exit. I suspect that the reactor is waiting on the threads to
>> finish, which they apparently don't do, and as for the wx integration, I
>> don't know, maybe wx's main loop is in a separate thread and it would be the
>> same problem. Does anyone know/have an idea or has anyone else experienced
>> this?
>> Thank you,
>> Gabriel
>> _______________________________________________
>> 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