views:

138

answers:

1

I am running an app using twisted and tkinter that sends the result to the server, waits for the server to send back a confirmation, and then exits. So, the function I use to exit is this:

def term():
    '''To end the program'''
    reactor.stop()
    root.quit()
    root.destroy()

This is then set in the factory and called in the dataReceived function of the protocol. I run it, and the program runs fine and even sends the necessary data and closes, but it also gives me the following error report:

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

Does anyone know why?

+1  A: 

You only need to call reactor.stop to exit: the root.quit() and root.destroy() calls are superfluous. Consider this short example which runs Twisted and Tk for three seconds and then exits:

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()
Jean-Paul Calderone
It is no longer giving me problems, thank you.
Nikwin