Console printing

Emile van Sebille emile at fenx.com
Fri Mar 16 20:57:08 EST 2001


Invoke pythone with the -u option

Emile van Sebille
emile at fenx.com


"Costas Menico" <costas at meezon.com> wrote in message
news:3ab2c183.4460238 at News.CIS.DFN.DE...
> 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