Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Spawing a thread and printing dots until it finishes

Reply
Thread Tools

Spawing a thread and printing dots until it finishes

 
 
pat
Guest
Posts: n/a
 
      04-22-2008
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!

 
Reply With Quote
 
 
 
 
pat
Guest
Posts: n/a
 
      04-22-2008
On Apr 22, 3:06 pm, pat <(E-Mail Removed)> wrote:
> 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...
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Spawing a thread and printing dots until it finishes sophie_newbie Python 9 04-24-2008 11:36 AM
Will a "system call" wait until the command finishes? sayoyo Sayoyo Ruby 1 02-15-2008 08:47 PM
STUMPED: IFRAME link won't load until XMLHTTP finishes!? jim.frantzen@gmail.com ASP .Net 5 08-29-2005 06:13 PM
STUMPED: IFRAME link won't load until XMLHTTP finishes!? jim.frantzen@gmail.com Javascript 4 08-29-2005 06:13 PM
Help on writing a timer class (cross platform thread spawing) Alfonso Morra C++ 1 07-18-2005 12:00 PM



Advertisments