[Twisted-Python] Twisted with wxPython in a thread

Hello, I can't find any examples of using Twisted with wxPython, were wx is in a seperate thread. I used to have one somewhere but can' t find it either. I'm looking because for some reason my code doesn't work (the GUI freezes), even though I use reactor.callFromThread() for Twisted calls from wx and wx.CallAfter() for wx calls from Twisted. Can anyone point me to an example? Thank you, Gabriel

On Tue, 2010-08-24 at 11:40 +0200, Gabriel Rossetti wrote:
Hello,
I can't find any examples of using Twisted with wxPython, were wx is in a seperate thread. I used to have one somewhere but can' t find it either. I'm looking because for some reason my code doesn't work (the GUI freezes), even though I use reactor.callFromThread() for Twisted calls from wx and wx.CallAfter() for wx calls from Twisted. Can anyone point me to an example?
I would expect that to work (assuming wx.CallAfter works). Can you post a minimal example of your code that demonstrates a freezing GUI?

On 08/24/2010 02:11 PM, Itamar Turner-Trauring wrote:
On Tue, 2010-08-24 at 11:40 +0200, Gabriel Rossetti wrote:
Hello,
I can't find any examples of using Twisted with wxPython, were wx is in a seperate thread. I used to have one somewhere but can' t find it either. I'm looking because for some reason my code doesn't work (the GUI freezes), even though I use reactor.callFromThread() for Twisted calls from wx and wx.CallAfter() for wx calls from Twisted. Can anyone point me to an example?
I would expect that to work (assuming wx.CallAfter works). Can you post a minimal example of your code that demonstrates a freezing GUI?
Thanks for the reply, I'm going to try some other things before I make a minimal example, keep you up to date, thanks

I have experience getting cherrypy (web server) and Twisted to play together nicely... As you know, reactor.callFromThread is necessary for waking-up twisted from a non-twisted thread. Getting both cherrypy and the reactor running required that I start cherrypy with a callback to run the reactor. I also needed to turn off twisted's signal handling and install my own signal handling to ensure proper shut down. Are you sure that wx.CallAfter is the right thing for wx calls from Twisted? Since Twisted is an event loop, it may not release control in the same fashion as other wx calls. Jason On Tue, Aug 24, 2010 at 5:40 AM, Gabriel Rossetti < gabriel.rossetti@arimaz.com> wrote:
Hello,
I can't find any examples of using Twisted with wxPython, were wx is in a seperate thread. I used to have one somewhere but can' t find it either. I'm looking because for some reason my code doesn't work (the GUI freezes), even though I use reactor.callFromThread() for Twisted calls from wx and wx.CallAfter() for wx calls from Twisted. Can anyone point me to an example?
Thank you, Gabriel
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
-- Jason Rennie Research Scientist, ITA Software 617-714-2645 http://www.itasoftware.com/

It may not indeed, but from what I've read it should, I'll look into that, thanks for the reply and idea. Gabriel On 08/24/2010 03:00 PM, Jason Rennie wrote:
I have experience getting cherrypy (web server) and Twisted to play together nicely... As you know, reactor.callFromThread is necessary for waking-up twisted from a non-twisted thread. Getting both cherrypy and the reactor running required that I start cherrypy with a callback to run the reactor. I also needed to turn off twisted's signal handling and install my own signal handling to ensure proper shut down.
Are you sure that wx.CallAfter is the right thing for wx calls from Twisted? Since Twisted is an event loop, it may not release control in the same fashion as other wx calls.
Jason
On Tue, Aug 24, 2010 at 5:40 AM, Gabriel Rossetti <gabriel.rossetti@arimaz.com <mailto:gabriel.rossetti@arimaz.com>> wrote:
Hello,
I can't find any examples of using Twisted with wxPython, were wx is in a seperate thread. I used to have one somewhere but can' t find it either. I'm looking because for some reason my code doesn't work (the GUI freezes), even though I use reactor.callFromThread() for Twisted calls from wx and wx.CallAfter() for wx calls from Twisted. Can anyone point me to an example?
Thank you, Gabriel
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com <mailto:Twisted-Python@twistedmatrix.com> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
-- Jason Rennie Research Scientist, ITA Software 617-714-2645 http://www.itasoftware.com/
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

On 08/24/2010 05:40 AM, Gabriel Rossetti wrote:
Hello,
I can't find any examples of using Twisted with wxPython, were wx is in a seperate thread. I used to have one somewhere but can' t find it either. I'm looking because for some reason my code doesn't work (the GUI freezes), even though I use reactor.callFromThread() for Twisted calls from wx and wx.CallAfter() for wx calls from Twisted. Can anyone point me to an example?
I've used a method for running twisted and wxPython in separate threads that was developed by someone at Solipsis (http://netofpeers.com). I've put the example that was on their web site (since removed) on mine: http://pangalactic.us/txwx/separate_thread_example.html You can see a less trivial application of it here: https://pangalactic.us/repo/ampchat ... in which I used that method in creating a wxpython-based client to David Ripton's "ampchat" (wxchatclient.py). This method has worked for me, whereas I've observed the same (freezing) behavior with wxreactor. Steve

On 08/24/2010 03:06 PM, Stephen Waterbury wrote:
On 08/24/2010 05:40 AM, Gabriel Rossetti wrote:
Hello,
I can't find any examples of using Twisted with wxPython, were wx is in a seperate thread. I used to have one somewhere but can' t find it either. I'm looking because for some reason my code doesn't work (the GUI freezes), even though I use reactor.callFromThread() for Twisted calls from wx and wx.CallAfter() for wx calls from Twisted. Can anyone point me to an example?
I've used a method for running twisted and wxPython in separate threads that was developed by someone at Solipsis (http://netofpeers.com). I've put the example that was on their web site (since removed) on mine: http://pangalactic.us/txwx/separate_thread_example.html
You can see a less trivial application of it here: https://pangalactic.us/repo/ampchat
... in which I used that method in creating a wxpython-based client to David Ripton's "ampchat" (wxchatclient.py). This method has worked for me, whereas I've observed the same (freezing) behavior with wxreactor.
Steve
Ok, so you put Twisted in a thread? I read in several posts that this posed problems, have you had any drawbacks? Gabriel

On 08/24/2010 09:22 AM, Gabriel Rossetti wrote:
On 08/24/2010 03:06 PM, Stephen Waterbury wrote:
On 08/24/2010 05:40 AM, Gabriel Rossetti wrote:
Hello,
I can't find any examples of using Twisted with wxPython, were wx is in a seperate thread. I used to have one somewhere but can' t find it either. I'm looking because for some reason my code doesn't work (the GUI freezes), even though I use reactor.callFromThread() for Twisted calls from wx and wx.CallAfter() for wx calls from Twisted. Can anyone point me to an example?
I've used a method for running twisted and wxPython in separate threads that was developed by someone at Solipsis (http://netofpeers.com). I've put the example that was on their web site (since removed) on mine: http://pangalactic.us/txwx/separate_thread_example.html
You can see a less trivial application of it here: https://pangalactic.us/repo/ampchat
... in which I used that method in creating a wxpython-based client to David Ripton's "ampchat" (wxchatclient.py). This method has worked for me, whereas I've observed the same (freezing) behavior with wxreactor.
Steve
Ok, so you put Twisted in a thread? I read in several posts that this posed problems, have you had any drawbacks?
I haven't observed any. Steve

On 08/24/2010 09:24 AM, Stephen Waterbury wrote:
On 08/24/2010 09:22 AM, Gabriel Rossetti wrote:
Ok, so you put Twisted in a thread? I read in several posts that this posed problems, have you had any drawbacks?
I haven't observed any.
Reflecting on this a little further (and with the caveat that I am a complete ignoramus on threading), it seems to me that problems happen when Twisted is not in the main thread. Note that in the example, the reactor starts first (i.e., before the wx event loop), so I guess it is in the main thread ... I haven't tried switching them, but if you do that or anything that breaks this method, please let me know -- as I say, I haven't seen it break (freeze or otherwise malfunction) yet. Steve

On Tue, 2010-08-24 at 15:22 +0200, Gabriel Rossetti wrote:
Ok, so you put Twisted in a thread? I read in several posts that this posed problems, have you had any drawbacks?
reactor.spawnProcess won't notice processes have exited on posix platforms (though you can fix this by installing your own SIGCHLD handler in the main thread that does callFromThread on t.i.process.reapAllProcesses).

On 08/24/2010 04:26 PM, Itamar Turner-Trauring wrote:
On Tue, 2010-08-24 at 15:22 +0200, Gabriel Rossetti wrote:
Ok, so you put Twisted in a thread? I read in several posts that this posed problems, have you had any drawbacks?
reactor.spawnProcess won't notice processes have exited on posix platforms (though you can fix this by installing your own SIGCHLD handler in the main thread that does callFromThread on t.i.process.reapAllProcesses).
Ok, thanks for the info, I'll look into this if I go for the twisted-in-a-thread version, although I may no longer be using reactor.spawnProcess myself but it is probably being used somewhere by Twisted so it's beter to do that.
participants (4)
-
Gabriel Rossetti
-
Itamar Turner-Trauring
-
Jason Rennie
-
Stephen Waterbury