Killing threads
costas at meezon.com
costas at meezon.com
Fri Mar 16 12:30:42 EST 2001
I have th program below. How does one go about kill a thread once
started? Why is there no method for killing threads? I thought del
would do it but obviously it doesn't.
Also the print in the run method does not print until a sys.exit() is
executed.
# Note: You cannot CTRL-BREAK out of this program in PythonWin.
# You have to kill it using the task manager.
import threading
import time
import sys
class wasteTime(threading.Thread):
def run(self):
# run forever
while 1:
print time.time()
time.sleep(1)
startTime=time.time()
th=wasteTime()
th.start()
while 1:
time.sleep(0.5)
if time.time()>startTime+5:
# I want to kill the th thread right here.
del th
sys.exit()
TIA
Costas
More information about the Python-list
mailing list