Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 11th, 2004, 10:51 AM
winwin winwin is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 21 winwin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
thread killing

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)

Thanks

Reply With Quote
  #2  
Old June 11th, 2004, 12:09 PM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 7
Send a message via MSN to Grim Archon
Quote:
Originally Posted by winwin
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)

Thanks

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.

Here was an interesting googled example:
http://aspn.activestate.com/ASPN/Co...on/Recipe/65222

grim
__________________
*** Experimental Python Markup CGI V2 ***

Reply With Quote
  #3  
Old June 14th, 2004, 08:27 AM
winwin winwin is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 21 winwin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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:

Code:
root = Tk()
event1 = threading.Event()
event1.set()


I have two problems in fact:
- 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:
Code:
    if not event1.isSet():
            break

Reply With Quote
  #4  
Old June 14th, 2004, 12:04 PM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 7
Send a message via MSN to Grim Archon
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.

grim

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > thread killing


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT