Connecting Tech Pros Worldwide Forums | Help | Site Map

Spawing a thread and printing dots until it finishes

pat
Guest
 
Posts: n/a
#1: Jun 27 '08
Hi, I'm trying to write a piece of code that spawns a thread and
prints dots every half second until the thread is finished. Code is
something like this:


import threading
class MyThread ( threading.Thread ):
def run ( self ):
myLongCommand...


import time

t = MyThread()
t.start()

while t.isAlive():
print "."
time.sleep(.5)

print "OK"


The thing is this doesn't print a dot every half second. It just
pauses for ages until the thread is finished and prints prints ".OK".
But if I take out the "time.sleep(.5)" line it will keep printing dots
really fast until the thread is finished. So it looks like its the
time.sleep(.5) bit that is messing this up somehow?

Any ideas?

Thanks!


pat
Guest
 
Posts: n/a
#2: Jun 27 '08

re: Spawing a thread and printing dots until it finishes


On Apr 22, 3:06 pm, pat <paulgeele...@gmail.comwrote:
Quote:
Hi, I'm trying to write a piece of code that spawns a thread and
prints dots every half second until the thread is finished. Code is
something like this:
>
import threading
class MyThread ( threading.Thread ):
def run ( self ):
myLongCommand...
>
import time
>
t = MyThread()
t.start()
>
while t.isAlive():
print "."
time.sleep(.5)
>
print "OK"
>
The thing is this doesn't print a dot every half second. It just
pauses for ages until the thread is finished and prints prints ".OK".
But if I take out the "time.sleep(.5)" line it will keep printing dots
really fast until the thread is finished. So it looks like its the
time.sleep(.5) bit that is messing this up somehow?
>
Any ideas?
>
Thanks!
Oh shite I meant to post that on the Python board. Here comes the
abuse...
Closed Thread