En Fri, 20 Feb 2009 14:47:27 -0200, jimzat <jim...@iname.com> escribió:
I am trying to create an app which will have a main window from which the user will launch other (children) windows. When I launch the child window I start a new thread which periodically polls another device and updates the child window accordingly. When I dismiss the child window the "polling" thread stays alive and then crashes with an exception when trying to write to the now defunct child window. How can I handle this? I want to either 1) have the destructor for the child window kill the spawned thread or 2) catch the exception within the "polling" thread and see that the child window is gone and then commit suicide.
1) make the child window set a flag in the thread (let's say, t.terminate = True). And make the polling thread check the flag periodically (you possibly already have a loop there - just break the loop when you detect that self.terminate became true)
2) catching an exception is as easy as enclosing the code in a try/except block. And "commit suicide" is just "exit from the run() method".
-- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list