ich habe ein Programm mit verschiedenen Threads, die sekündlich einen bestimmten Status abfragen und ihn anschließend der GUI (Tkinter) mitteilen.
Das Problem ist nur, dass wenn ich das Programm beende, anscheinend Tkinter-Objekte vorher zerstört werden, die Threads noch im Hintergrund laufen und auf die GUI zugreifen wollen und es anschließend zu einer Exception führt (nicht immer, aber eben manchmal).
Hier die Fehlermeldung:
Code: Alles auswählen
Unhandled exception in thread started by <bound method Controller.watchPortStatus of <src.controller.Controller.Controller object at 0x00C1AB30>>
Traceback (most recent call last):
File "C:\Documents and Settings\stdi3650\My Documents\Aptana Studio 3 Workspace\COM-CommunicatorV4\src\controller\Controller.py", line 102, in watchPortStatus
portListButtons[i]['background'] = 'green'
File "C:\Python25\lib\lib-tk\Tkinter.py", line 1204, in __setitem__
self.configure({key: value})
File "C:\Python25\lib\lib-tk\Tkinter.py", line 1197, in configure
return self._configure('configure', cnf, kw)
File "C:\Python25\lib\lib-tk\Tkinter.py", line 1188, in _configure
self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
_tkinter.TclError: invalid command name ".12709320.12709680.12718848"
Code: Alles auswählen
def watchPortStatus(self, portListButtons): # Funktion, die von einem separaten Thread ausgeführt wird.
while self.com.connectionIsOpen():
with self._port_button_lock:
portStatus = self.com.getPortStatusFromDevice()
for i in range(len(portListButtons)):
currentPortMask = (1 << i)
if (currentPortMask & portStatus == currentPortMask):
portListButtons[i]['background'] = 'green'
else:
portListButtons[i]['background'] = 'red'
time.sleep(1)
Danke im Voraus!
L. G.
Steffo