Console printing
Costas Menico
costas at meezon.com
Fri Mar 16 20:47:05 EST 2001
Why does the following program only prints the output (in the run
method) when the while loop terminates? Please note that this is
running in a thread. I though a sleep() is supposed to allow time for
console to update itself. I am using Pythonwin.
import threading
import time
import sys
class wasteTime(threading.Thread):
def run(self):
# run forever
self.running=1
while self.running:
print time.time()
time.sleep(1)
def stop(self):
self.running=0
th=wasteTime()
print "Start thread"
startTime=time.time()
th.start()
while time.time()<startTime+5:
time.sleep(1)
# I want to kill the th thread right here.
th.stop()
print "Finished Thread"
sys.exit()
#Costas
More information about the Python-list
mailing list