June 11th, 2004, 11:51 AM
I programmed this graphical interface with Tkinter, and in order to have it operational all the time I introduced threads in it.
But if you quit the interface the other threads seem to be running still.
How would you kill all the threads before quiting the interface? Or is there a "clean" way of doing things that resolves this problem automatically (I admit I am more of a python mac guyver but not as good, trying to put things together with my swiss knif)
June 11th, 2004, 01:09 PM
There is no direct way of killing a thread in Python. One approach is to set a flag that is tested by the thread code periodically. Basically, you ask the thread to terminate and then hope that it does. The main thread should wait on an a threading.Event - if you set a timeout period then you can test to see if the flag is-set-or-not after the wait terminates. Dependent on the result you can modify your program exit strategy.
Originally Posted by winwin
Here was an interesting googled example:
June 14th, 2004, 09:27 AM
Yeah thanks it works quite okay! Not that easy i my opinion, but it works all the same (i would have prefered something like the good old signals I used when i did some C programing that kill anything anytime...)
I'm getting to where I want to go, but I saw something very strange and I have trouble explaining it:
I have two problems in fact:
root = Tk()
event1 = threading.Event()
- when I put the event after the root creation, everything doesn't quit. The first thread to make the flag test does quit but then it seems the root.mainloop() starts again before all the threads do their flag test, and so the flag is set to True again...
- when i put it before, then my sub threads see the event as False as soon as they are started... so they quit right away (they do this test one in a while:
if not event1.isSet():
June 14th, 2004, 01:04 PM
I would normally assume that the Tkinter thread is the main thread from which you launch the other worker threads. In which case I don't see why your root.mainloop is being called again.
What you have posted tells me nothing I am afraid - I need more detail/code.