[Twisted-Python] wxpython, threadselectreactor and thread
I have a wxpython application that work with twsited 2.0 on win and linux. In these days I'm "porting" it from twisted 1.3 to 2.0 + threadselectreactor, but not all work well. Into my application I use: callLater threads.deferToThread with some addCallBack Three problems: 1) Sometime then I open and close my application I receive this error: Unhandled exception in thread started by <bound method Thread.__bootstrap of <Thread(Thread-1, stopped daemon)>> Traceback (most recent call last): File "C:\Python23\lib\threading.py", line 451, in __bootstrap self.__stop() File "C:\Python23\lib\threading.py", line 460, in __stop self.__block.notifyAll() File "C:\Python23\lib\threading.py", line 256, in notifyAll self.notify(len(self.__waiters)) File "C:\Python23\lib\threading.py", line 238, in notify currentThread() # for side-effect TypeError: 'NoneType' object is not callable 2) Then I call with threads.deferToThread a method that make a blocking work, and after it open a new frame, the frame is opened, but if I want to close the first frame and the second frame (with the "X" on the frame), the application don't close. Into the task manager (on win) or into /proc/"pid" I see that the process (python.exe) are alive and have three threads. I attach a simple code that reproduce this problem. 3) Why into your demo the reactor.stop() work and into my code I receive this error: RuntimeError: can't stop reactor that isn't running I use the same code initialization of the demo. Thanks a lot, Michele
On Mon, 2005-05-30 at 14:35 +0200, Michele Petrazzo wrote:
3) Why into your demo the reactor.stop() work and into my code I receive this error: RuntimeError: can't stop reactor that isn't running I use the same code initialization of the demo.
You are not calling reactor.run() anywhere, as far as I can tell.
On May 30, 2005, at 8:17 AM, Itamar Shtull-Trauring wrote:
On Mon, 2005-05-30 at 14:35 +0200, Michele Petrazzo wrote:
3) Why into your demo the reactor.stop() work and into my code I receive this error: RuntimeError: can't stop reactor that isn't running I use the same code initialization of the demo.
You are not calling reactor.run() anywhere, as far as I can tell.
That shouldn't be the problem.. reactor.interleave() is being called. reactor.interleave is effectively a non-blocking version of stop. -bob
On May 30, 2005, at 9:12 AM, Bob Ippolito wrote:
On May 30, 2005, at 8:17 AM, Itamar Shtull-Trauring wrote:
On Mon, 2005-05-30 at 14:35 +0200, Michele Petrazzo wrote:
3) Why into your demo the reactor.stop() work and into my code I receive this error: RuntimeError: can't stop reactor that isn't running I use the same code initialization of the demo.
You are not calling reactor.run() anywhere, as far as I can tell.
That shouldn't be the problem.. reactor.interleave() is being called. reactor.interleave is effectively a non-blocking version of stop.
That should be, non-blocking version of *run*. -bob
Itamar Shtull-Trauring wrote:
On Mon, 2005-05-30 at 14:35 +0200, Michele Petrazzo wrote:
3) Why into your demo the reactor.stop() work and into my code I receive this error: RuntimeError: can't stop reactor that isn't running I use the same code initialization of the demo.
You are not calling reactor.run() anywhere, as far as I can tell.
My understanding is you call reactor.interleave **NOT** reactor.run with threadedselectreactor. For wx I use reactor.interleave(wx.CallAfter) in my App.OnInit method and it works fine. There IS an issue with the wx MainLoop not exiting when my last frame is closed (I think this is because wx still "sees" the reactor thread) so I use wx.GetApp().Exit() to terminate the wx MainLoop manually. Shawn Church http://SChurchComputers.com
On May 30, 2005, at 5:35 AM, Michele Petrazzo wrote:
I have a wxpython application that work with twsited 2.0 on win and linux. In these days I'm "porting" it from twisted 1.3 to 2.0 + threadselectreactor, but not all work well. Into my application I use: callLater threads.deferToThread with some addCallBack
This example segfaults on Mac OS X (python 2.4.1, twisted svn, wxPython 2.6). I'm going to blame wxPython unless you can prove that threadedselectreactor has some weird interaction with threads in an otherwise sane environment. Are you sure that it's allowed to create frames in a separate thread like that? -bob
This example segfaults on Mac OS X (python 2.4.1, twisted svn, wxPython 2.6). I'm going to blame wxPython unless you can prove that threadedselectreactor has some weird interaction with threads in an otherwise sane environment. Are you sure that it's allowed to create frames in a separate thread like that?
It is generally not allowed to make wx calls (except wx.CallAfter and the like) from another thread than the wx main loop. It can be the source of non-deterministic crashes (depending on the platform). Regards Antoine.
Bob Ippolito wrote:
On May 30, 2005, at 5:35 AM, Michele Petrazzo wrote:
I have a wxpython application that work with twsited 2.0 on win and linux. In these days I'm "porting" it from twisted 1.3 to 2.0 + threadselectreactor, but not all work well. Into my application I use: callLater threads.deferToThread with some addCallBack
This example segfaults on Mac OS X (python 2.4.1, twisted svn, wxPython 2.6). I'm going to blame wxPython unless you can prove that threadedselectreactor has some weird interaction with threads in an otherwise sane environment. Are you sure that it's allowed to create frames in a separate thread like that?
-bob
You are right, on my linux-box I receive a: Xlib: unexpected async reply (sequence 0x4a2)! Xlib: sequence lost (0x104a2 > 0x4e8) in reply type 0x0! But on win it work, sorry! My first problem leave, so sometime, but I don't understand when, on both of my systems (win, lin), I receive e thread error (the first question on my first mail). If someone want try my application, for reproduce the problem, I can publish it on a web site. It's only a little problem: it's an hylafax client, so for work you must have a hylafax server. Thanks, Michele
Michele Petrazzo wrote:
1) Sometime then I open and close my application I receive this error:
Unhandled exception in thread started by <bound method Thread.__bootstrap of <Thread(Thread-1, stopped daemon)>> Traceback (most recent call last): File "C:\Python23\lib\threading.py", line 451, in __bootstrap self.__stop() File "C:\Python23\lib\threading.py", line 460, in __stop self.__block.notifyAll() File "C:\Python23\lib\threading.py", line 256, in notifyAll self.notify(len(self.__waiters)) File "C:\Python23\lib\threading.py", line 238, in notify currentThread() # for side-effect TypeError: 'NoneType' object is not callable
After a lot of tries, I see that this problem, depend on _sendToMain method of ThreadedSelectReactor class. If I put a simple try: SomeCode except: print 'exception on _sendToMain', I see that I have no more errors, but only a simple print. I don't know why this error occur, but I hope that this little hack can help the developers. Michele
participants (5)
-
Antoine Pitrou
-
Bob Ippolito
-
Itamar Shtull-Trauring
-
Michele Petrazzo
-
Shawn Church