Spawing a thread and printing dots until it finishes

P

pat

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!
 
P

pat

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...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,265
Latest member
TodLarocca

Latest Threads

Top