我使用twisted和tkinter运行应用程序,将结果发送到服务器,等待服务器发回确认,然后退出。所以,我用来退出的功能是:
def term():
'''To end the program'''
reactor.stop()
root.quit()
root.destroy()
然后在工厂中设置它,并在协议的dataReceived函数中调用。我运行它,程序运行正常,甚至发送必要的数据并关闭,但它也给我以下错误报告:
Unhandled error in Deferred:
Traceback (most recent call last):
File "D:\Python25\Lib\site-packages\twisted\internet\base.py", line 1128, in run
self.mainLoop()
File "D:\Python25\Lib\site-packages\twisted\internet\base.py", line 1137, in mainLoop
self.runUntilCurrent()
File "D:\Python25\Lib\site-packages\twisted\internet\base.py", line 757, in runUntilCurrent
call.func(*call.args, **call.kw)
File "D:\Python25\Lib\site-packages\twisted\internet\task.py", line 114, in __call__
d = defer.maybeDeferred(self.f, *self.a, **self.kw)
--- <exception caught here> ---
File "D:\Python25\Lib\site-packages\twisted\internet\defer.py", line 106, in maybeDeferred
result = f(*args, **kw)
File "D:\Python25\lib\lib-tk\Tkinter.py", line 917, in update
self.tk.call('update')
_tkinter.TclError: can't invoke "update" command: application has been destroyed
有谁知道为什么?
答案 0 :(得分:1)
您只需拨打reactor.stop
即可退出:root.quit()
和root.destroy()
来电是多余的。考虑这个简短的例子,它运行Twisted和Tk三秒然后退出:
import Tkinter
from twisted.internet import tksupport
root = Tkinter.Tk()
tksupport.install(root)
from twisted.internet import reactor
reactor.callLater(3, reactor.stop)
reactor.run()