[Twisted-Python] Conflict between Tkinter.mainloop() and twisted.internet.reactor.run()
Hi all, I'm writing a program with Twisted and use Tkinter to realize the GUI interface. However, it seems that I can not run both Tkinter.mainloop() and twisted.internet.reactor.run() in the same thread because they will block the other. I tried to program a button in Tkinter and when the button is pressed, it will start a new thread using module threading, and call a function with the contend of reactor.listenTCP(PORT, file_trans_service.getFileTransCtrlServFactory() reactor.run() But it will raise an exception as follows: --- <exception caught here> --- File "F:\Python27\lib\site-packages\twisted\internet\base.py", line 426, in _continueFiring callable(*args, **kwargs) File "F:\Python27\lib\site-packages\twisted\internet\base.py", line 1164, in _reallyStartRunning self._handleSignals() File "F:\Python27\lib\site-packages\twisted\internet\posixbase.py", line 292, in _handleSignals _SignalReactorMixin._handleSignals(self) File "F:\Python27\lib\site-packages\twisted\internet\base.py", line 1129, in _handleSignals signal.signal(signal.SIGINT, self.sigInt) exceptions.ValueError: signal only works in main thread And I also tried to run twisted.internet.reactor.run() in the main thread, and use module threading or reactor.callInThread() to run Tkinter.mainloop(). The interface will be displayed, but not responding. Any one knows how to solve this problem? I just need a Template to realize the Twisted with GUI. Very appreciated! Best, Hanks
The answer is here: http://twistedmatrix.com/documents/8.2.0/api/twisted.internet.tksupport.html use tksupport.install() instead of Tkinter.run() 2012/3/30 hz hanks <hankshz@gmail.com>:
Hi all,
I'm writing a program with Twisted and use Tkinter to realize the GUI interface. However, it seems that I can not run both Tkinter.mainloop() and twisted.internet.reactor.run() in the same thread because they will block the other. I tried to program a button in Tkinter and when the button is pressed, it will start a new thread using module threading, and call a function with the contend of
reactor.listenTCP(PORT, file_trans_service.getFileTransCtrlServFactory() reactor.run()
But it will raise an exception as follows: --- <exception caught here> --- File "F:\Python27\lib\site-packages\twisted\internet\base.py", line 426, in _continueFiring callable(*args, **kwargs) File "F:\Python27\lib\site-packages\twisted\internet\base.py", line 1164, in _reallyStartRunning self._handleSignals() File "F:\Python27\lib\site-packages\twisted\internet\posixbase.py", line 292, in _handleSignals _SignalReactorMixin._handleSignals(self) File "F:\Python27\lib\site-packages\twisted\internet\base.py", line 1129, in _handleSignals signal.signal(signal.SIGINT, self.sigInt) exceptions.ValueError: signal only works in main thread
And I also tried to run twisted.internet.reactor.run() in the main thread, and use module threading or reactor.callInThread() to run Tkinter.mainloop(). The interface will be displayed, but not responding.
Any one knows how to solve this problem? I just need a Template to realize the Twisted with GUI. Very appreciated!
Best, Hanks
On 03/30/2012 06:36 PM, hz hanks wrote:
Any one knows how to solve this problem? I just need a Template to realize the Twisted with GUI. Very appreciated!
http://twistedmatrix.com/documents/current/core/howto/choosing-reactor.html#...
participants (2)
-
hz hanks
-
Itamar Turner-Trauring