[Tutor] How to enable pausing my timer.py ?

Christian Wyglendowski Christian.Wyglendowski at greenville.edu
Wed Jul 7 22:56:31 CEST 2004

> -----Original Message-----
> > I just realized that my stopwatch was really a timer: you set it to
> beep
> > after a length of time you enter; it stops and beeps when that time
> is up.
> You could make it even more general purpose buy putting the 
> guts of it in a function called say, doAfter()
> def doAfter(t,f):
> ''' t is the time required and f is a function to be executed
>     after t expires.'''
> Thus in your current case you would call
> doAfter( t, lambda : winsound.beep(500) )

Which is I believe what the Timer object in the threading module lets
you do:

>>> import threading, sys
>>> t = threading.Timer(10, sys.stdout.write, ['Done'])
>>> t.start()
...(waits for 10 secs)...
>>> Done

Documentation for the threading.Timer object can be found here:

In order to pause one, I think you would need to send the thread a
signal, but that sort of magic is beyond the skill of *this* python hack
;-)  Maybe I'll play around with it and see if I can figure it out.


> Alan G.
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor

More information about the Tutor mailing list