| 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
| 2 | <html> |
| 3 | <head> |
| 4 | <link rel="STYLESHEET" href="lib.css" type='text/css' /> |
| 5 | <link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" /> |
| 6 | <link rel='start' href='../index.html' title='Python Documentation Index' /> |
| 7 | <link rel="first" href="lib.html" title='Python Library Reference' /> |
| 8 | <link rel='contents' href='contents.html' title="Contents" /> |
| 9 | <link rel='index' href='genindex.html' title='Index' /> |
| 10 | <link rel='last' href='about.html' title='About this document...' /> |
| 11 | <link rel='help' href='about.html' title='About this document...' /> |
| 12 | <link rel="prev" href="thread-objects.html" /> |
| 13 | <link rel="parent" href="module-threading.html" /> |
| 14 | <link rel="next" href="module-dummythread.html" /> |
| 15 | <meta name='aesop' content='information' /> |
| 16 | <title>7.5.7 Timer Objects </title> |
| 17 | </head> |
| 18 | <body> |
| 19 | <DIV CLASS="navigation"> |
| 20 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> |
| 21 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> |
| 22 | <tr> |
| 23 | <td class='online-navigation'><a rel="prev" title="7.5.6 Thread Objects" |
| 24 | href="thread-objects.html"><img src='../icons/previous.png' |
| 25 | border='0' height='32' alt='Previous Page' width='32' /></A></td> |
| 26 | <td class='online-navigation'><a rel="parent" title="7.5 threading " |
| 27 | href="module-threading.html"><img src='../icons/up.png' |
| 28 | border='0' height='32' alt='Up One Level' width='32' /></A></td> |
| 29 | <td class='online-navigation'><a rel="next" title="7.6 dummy_thread " |
| 30 | href="module-dummythread.html"><img src='../icons/next.png' |
| 31 | border='0' height='32' alt='Next Page' width='32' /></A></td> |
| 32 | <td align="center" width="100%">Python Library Reference</td> |
| 33 | <td class='online-navigation'><a rel="contents" title="Table of Contents" |
| 34 | href="contents.html"><img src='../icons/contents.png' |
| 35 | border='0' height='32' alt='Contents' width='32' /></A></td> |
| 36 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' |
| 37 | border='0' height='32' alt='Module Index' width='32' /></a></td> |
| 38 | <td class='online-navigation'><a rel="index" title="Index" |
| 39 | href="genindex.html"><img src='../icons/index.png' |
| 40 | border='0' height='32' alt='Index' width='32' /></A></td> |
| 41 | </tr></table> |
| 42 | <div class='online-navigation'> |
| 43 | <b class="navlabel">Previous:</b> |
| 44 | <a class="sectref" rel="prev" href="thread-objects.html">7.5.6 Thread Objects</A> |
| 45 | <b class="navlabel">Up:</b> |
| 46 | <a class="sectref" rel="parent" href="module-threading.html">7.5 threading </A> |
| 47 | <b class="navlabel">Next:</b> |
| 48 | <a class="sectref" rel="next" href="module-dummythread.html">7.6 dummy_thread </A> |
| 49 | </div> |
| 50 | <hr /></div> |
| 51 | </DIV> |
| 52 | <!--End of Navigation Panel--> |
| 53 | |
| 54 | <H2><A NAME="SECTION009570000000000000000"></A><A NAME="timer-objects"></A> |
| 55 | <BR> |
| 56 | 7.5.7 Timer Objects |
| 57 | </H2> |
| 58 | |
| 59 | <P> |
| 60 | This class represents an action that should be run only after a |
| 61 | certain amount of time has passed -- a timer. <tt class="class">Timer</tt> is a |
| 62 | subclass of <tt class="class">Thread</tt> and as such also functions as an example of |
| 63 | creating custom threads. |
| 64 | |
| 65 | <P> |
| 66 | Timers are started, as with threads, by calling their <tt class="method">start()</tt> |
| 67 | method. The timer can be stopped (before its action has begun) by |
| 68 | calling the <tt class="method">cancel()</tt> method. The interval the timer will |
| 69 | wait before executing its action may not be exactly the same as the |
| 70 | interval specified by the user. |
| 71 | |
| 72 | <P> |
| 73 | For example: |
| 74 | <div class="verbatim"><pre> |
| 75 | def hello(): |
| 76 | print "hello, world" |
| 77 | |
| 78 | t = Timer(30.0, hello) |
| 79 | t.start() # after 30 seconds, "hello, world" will be printed |
| 80 | </pre></div> |
| 81 | |
| 82 | <P> |
| 83 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 84 | <td><nobr><b><span class="typelabel">class</span> <tt id='l2h-2747' xml:id='l2h-2747' class="class">Timer</tt></b>(</nobr></td> |
| 85 | <td><var>interval, function, args=[], kwargs={}</var>)</td></tr></table></dt> |
| 86 | <dd> |
| 87 | Create a timer that will run <var>function</var> with arguments <var>args</var> and |
| 88 | keyword arguments <var>kwargs</var>, after <var>interval</var> seconds have passed. |
| 89 | </dl> |
| 90 | |
| 91 | <P> |
| 92 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 93 | <td><nobr><b><tt id='l2h-2748' xml:id='l2h-2748' class="method">cancel</tt></b>(</nobr></td> |
| 94 | <td><var></var>)</td></tr></table></dt> |
| 95 | <dd> |
| 96 | Stop the timer, and cancel the execution of the timer's action. This |
| 97 | will only work if the timer is still in its waiting stage. |
| 98 | </dl> |
| 99 | |
| 100 | <DIV CLASS="navigation"> |
| 101 | <div class='online-navigation'> |
| 102 | <p></p><hr /> |
| 103 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> |
| 104 | <tr> |
| 105 | <td class='online-navigation'><a rel="prev" title="7.5.6 Thread Objects" |
| 106 | href="thread-objects.html"><img src='../icons/previous.png' |
| 107 | border='0' height='32' alt='Previous Page' width='32' /></A></td> |
| 108 | <td class='online-navigation'><a rel="parent" title="7.5 threading " |
| 109 | href="module-threading.html"><img src='../icons/up.png' |
| 110 | border='0' height='32' alt='Up One Level' width='32' /></A></td> |
| 111 | <td class='online-navigation'><a rel="next" title="7.6 dummy_thread " |
| 112 | href="module-dummythread.html"><img src='../icons/next.png' |
| 113 | border='0' height='32' alt='Next Page' width='32' /></A></td> |
| 114 | <td align="center" width="100%">Python Library Reference</td> |
| 115 | <td class='online-navigation'><a rel="contents" title="Table of Contents" |
| 116 | href="contents.html"><img src='../icons/contents.png' |
| 117 | border='0' height='32' alt='Contents' width='32' /></A></td> |
| 118 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' |
| 119 | border='0' height='32' alt='Module Index' width='32' /></a></td> |
| 120 | <td class='online-navigation'><a rel="index" title="Index" |
| 121 | href="genindex.html"><img src='../icons/index.png' |
| 122 | border='0' height='32' alt='Index' width='32' /></A></td> |
| 123 | </tr></table> |
| 124 | <div class='online-navigation'> |
| 125 | <b class="navlabel">Previous:</b> |
| 126 | <a class="sectref" rel="prev" href="thread-objects.html">7.5.6 Thread Objects</A> |
| 127 | <b class="navlabel">Up:</b> |
| 128 | <a class="sectref" rel="parent" href="module-threading.html">7.5 threading </A> |
| 129 | <b class="navlabel">Next:</b> |
| 130 | <a class="sectref" rel="next" href="module-dummythread.html">7.6 dummy_thread </A> |
| 131 | </div> |
| 132 | </div> |
| 133 | <hr /> |
| 134 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> |
| 135 | </DIV> |
| 136 | <!--End of Navigation Panel--> |
| 137 | <ADDRESS> |
| 138 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. |
| 139 | </ADDRESS> |
| 140 | </BODY> |
| 141 | </HTML> |