@@ -82,6 +82,10 @@ \section{\module{threading} ---
8282A class that represents a thread of control. This class can be safely subclassed in a limited fashion.
8383\end {classdesc* }
8484
85+ \begin {classdesc* }{Timer}{}
86+ A thread that executes a function after a specified interval has passed.
87+ \end {classdesc* }
88+
8589Detailed interfaces for the objects are documented below.
8690
8791The design of this module is loosely based on Java's threading model.
@@ -595,3 +599,35 @@ \subsection{Thread Objects \label{thread-objects}}
595599The entire Python program exits when no active non-daemon
596600threads are left.
597601\end {methoddesc }
602+
603+
604+ \subsection {Timer Objects \label {timer-objects } }
605+
606+ This class represents an action that should be run only after a certain amount
607+ of time has passed --- a timer. \class {Timer} is a subclass of \class {Thread} and
608+ as such also functions as an example of creating custom threads.
609+
610+ Timers are started, as with threads, by calling their \method {start()} method. The
611+ timer can be stopped (before its action has begun) by calling the
612+ \method {cancel()} method. The interval the timer will wait before executing
613+ its action may not be exactly the same as the interval specified by the
614+ user.
615+
616+ For example:
617+ \begin {verbatim }
618+ def hello():
619+ print "hello, world"
620+
621+ t = Timer(30.0, hello)
622+ t.start() # after 30 seconds, "hello, world" will be printed
623+ \end {verbatim }
624+
625+ \begin {classdesc }{Timer}{interval, function, args=[], kwargs=\{\} }
626+ Create a timer that will run \var {function} with arguments \var {args} and
627+ keyword arguments \var {kwargs}, after \var {interval} seconds have passed.
628+ \end {classdesc }
629+
630+ \begin {methoddesc }{cancel}{}
631+ Stop the timer, and cancel the execution of the timer's action. This will only
632+ work if the timer is still in its waiting stage.
633+ \end {methoddesc }
0 commit comments