Spawing a thread and printing dots until it finishes

Discussion in 'C++' started by pat, Apr 22, 2008.

  1. pat

    pat Guest

    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, Apr 22, 2008
    #1
    1. Advertising

  2. pat

    pat Guest

    On Apr 22, 3:06 pm, pat <> 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...
     
    pat, Apr 22, 2008
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    5
    Views:
    742
  2. Alfonso Morra
    Replies:
    1
    Views:
    434
    Alfonso Morra
    Jul 18, 2005
  3. sophie_newbie
    Replies:
    9
    Views:
    254
    sophie_newbie
    Apr 24, 2008
  4. sayoyo Sayoyo
    Replies:
    1
    Views:
    229
    Reacher
    Feb 15, 2008
  5. Replies:
    4
    Views:
    158
Loading...

Share This Page