[Tutor] alternative to time.sleep()

alan.gauld@bt.com alan.gauld@bt.com
Mon, 8 Jul 2002 17:13:56 +0100


> I'm looking for an alternative to time.sleep() that will visually
> countdown/countup the sleep time and can be paused and resumed at any
> point.  Any ideas?

This what you mean?

def visualSleep(t):
   try:
      s = 0
      while s < t:
        print "Sleeping for %d Seconds" % s
        time.sleep(1)
        s += 1
   except: return s

Hit Ctrl C to trigger the exception and get the 
current 'time' back. It only works for integral seconds 
but you could use a multiplies to resolve to milliseconds 
if you really want!

You can do clever things to make the string update in 
place but thats too fancy for me :-)

Alan G