1

我正在使用 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

有谁知道为什么?

4

1 回答 1

1

你只需要调用reactor.stop退出:root.quit()androot.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()
于 2009-11-12T15:42:48.563 回答