Connecting Tech Pros Worldwide Help | Site Map

Spawing a thread and printing dots until it finishes

 
LinkBack Thread Tools Search this Thread
  #1  
Old June 27th, 2008, 04:38 PM
pat
Guest
 
Posts: n/a
Default Spawing a thread and printing dots until it finishes

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!


  #2  
Old June 27th, 2008, 04:38 PM
pat
Guest
 
Posts: n/a
Default 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...
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.