Commit | Line | Data |
---|---|---|
920dae64 AT |
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="next" href="thread-objects.html" /> | |
13 | <link rel="prev" href="semaphore-objects.html" /> | |
14 | <link rel="parent" href="module-threading.html" /> | |
15 | <link rel="next" href="thread-objects.html" /> | |
16 | <meta name='aesop' content='information' /> | |
17 | <title>7.5.5 Event Objects </title> | |
18 | </head> | |
19 | <body> | |
20 | <DIV CLASS="navigation"> | |
21 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> | |
22 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
23 | <tr> | |
24 | <td class='online-navigation'><a rel="prev" title="7.5.4.1 Semaphore Example" | |
25 | href="semaphore-examples.html"><img src='../icons/previous.png' | |
26 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
27 | <td class='online-navigation'><a rel="parent" title="7.5 threading " | |
28 | href="module-threading.html"><img src='../icons/up.png' | |
29 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
30 | <td class='online-navigation'><a rel="next" title="7.5.6 Thread Objects" | |
31 | href="thread-objects.html"><img src='../icons/next.png' | |
32 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
33 | <td align="center" width="100%">Python Library Reference</td> | |
34 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
35 | href="contents.html"><img src='../icons/contents.png' | |
36 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
37 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
38 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
39 | <td class='online-navigation'><a rel="index" title="Index" | |
40 | href="genindex.html"><img src='../icons/index.png' | |
41 | border='0' height='32' alt='Index' width='32' /></A></td> | |
42 | </tr></table> | |
43 | <div class='online-navigation'> | |
44 | <b class="navlabel">Previous:</b> | |
45 | <a class="sectref" rel="prev" href="semaphore-examples.html">7.5.4.1 Semaphore Example</A> | |
46 | <b class="navlabel">Up:</b> | |
47 | <a class="sectref" rel="parent" href="module-threading.html">7.5 threading </A> | |
48 | <b class="navlabel">Next:</b> | |
49 | <a class="sectref" rel="next" href="thread-objects.html">7.5.6 Thread Objects</A> | |
50 | </div> | |
51 | <hr /></div> | |
52 | </DIV> | |
53 | <!--End of Navigation Panel--> | |
54 | ||
55 | <H2><A NAME="SECTION009550000000000000000"></A><A NAME="event-objects"></A> | |
56 | <BR> | |
57 | 7.5.5 Event Objects | |
58 | </H2> | |
59 | ||
60 | <P> | |
61 | This is one of the simplest mechanisms for communication between | |
62 | threads: one thread signals an event and other threads wait for it. | |
63 | ||
64 | <P> | |
65 | An event object manages an internal flag that can be set to true with | |
66 | the <tt class="method">set()</tt> method and reset to false with the <tt class="method">clear()</tt> | |
67 | method. The <tt class="method">wait()</tt> method blocks until the flag is true. | |
68 | ||
69 | <P> | |
70 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
71 | <td><nobr><b><span class="typelabel">class</span> <tt id='l2h-2733' xml:id='l2h-2733' class="class">Event</tt></b>(</nobr></td> | |
72 | <td><var></var>)</td></tr></table></dt> | |
73 | <dd> | |
74 | The internal flag is initially false. | |
75 | </dl> | |
76 | ||
77 | <P> | |
78 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
79 | <td><nobr><b><tt id='l2h-2734' xml:id='l2h-2734' class="method">isSet</tt></b>(</nobr></td> | |
80 | <td><var></var>)</td></tr></table></dt> | |
81 | <dd> | |
82 | Return true if and only if the internal flag is true. | |
83 | </dl> | |
84 | ||
85 | <P> | |
86 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
87 | <td><nobr><b><tt id='l2h-2735' xml:id='l2h-2735' class="method">set</tt></b>(</nobr></td> | |
88 | <td><var></var>)</td></tr></table></dt> | |
89 | <dd> | |
90 | Set the internal flag to true. | |
91 | All threads waiting for it to become true are awakened. | |
92 | Threads that call <tt class="method">wait()</tt> once the flag is true will not block | |
93 | at all. | |
94 | </dl> | |
95 | ||
96 | <P> | |
97 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
98 | <td><nobr><b><tt id='l2h-2736' xml:id='l2h-2736' class="method">clear</tt></b>(</nobr></td> | |
99 | <td><var></var>)</td></tr></table></dt> | |
100 | <dd> | |
101 | Reset the internal flag to false. | |
102 | Subsequently, threads calling <tt class="method">wait()</tt> will block until | |
103 | <tt class="method">set()</tt> is called to set the internal flag to true again. | |
104 | </dl> | |
105 | ||
106 | <P> | |
107 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
108 | <td><nobr><b><tt id='l2h-2737' xml:id='l2h-2737' class="method">wait</tt></b>(</nobr></td> | |
109 | <td><var></var><big>[</big><var>timeout</var><big>]</big><var></var>)</td></tr></table></dt> | |
110 | <dd> | |
111 | Block until the internal flag is true. | |
112 | If the internal flag is true on entry, return immediately. Otherwise, | |
113 | block until another thread calls <tt class="method">set()</tt> to set the flag to | |
114 | true, or until the optional timeout occurs. | |
115 | ||
116 | <P> | |
117 | When the timeout argument is present and not <code>None</code>, it should be a | |
118 | floating point number specifying a timeout for the operation in | |
119 | seconds (or fractions thereof). | |
120 | </dl> | |
121 | ||
122 | <P> | |
123 | ||
124 | <DIV CLASS="navigation"> | |
125 | <div class='online-navigation'> | |
126 | <p></p><hr /> | |
127 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
128 | <tr> | |
129 | <td class='online-navigation'><a rel="prev" title="7.5.4.1 Semaphore Example" | |
130 | href="semaphore-examples.html"><img src='../icons/previous.png' | |
131 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
132 | <td class='online-navigation'><a rel="parent" title="7.5 threading " | |
133 | href="module-threading.html"><img src='../icons/up.png' | |
134 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
135 | <td class='online-navigation'><a rel="next" title="7.5.6 Thread Objects" | |
136 | href="thread-objects.html"><img src='../icons/next.png' | |
137 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
138 | <td align="center" width="100%">Python Library Reference</td> | |
139 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
140 | href="contents.html"><img src='../icons/contents.png' | |
141 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
142 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
143 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
144 | <td class='online-navigation'><a rel="index" title="Index" | |
145 | href="genindex.html"><img src='../icons/index.png' | |
146 | border='0' height='32' alt='Index' width='32' /></A></td> | |
147 | </tr></table> | |
148 | <div class='online-navigation'> | |
149 | <b class="navlabel">Previous:</b> | |
150 | <a class="sectref" rel="prev" href="semaphore-examples.html">7.5.4.1 Semaphore Example</A> | |
151 | <b class="navlabel">Up:</b> | |
152 | <a class="sectref" rel="parent" href="module-threading.html">7.5 threading </A> | |
153 | <b class="navlabel">Next:</b> | |
154 | <a class="sectref" rel="next" href="thread-objects.html">7.5.6 Thread Objects</A> | |
155 | </div> | |
156 | </div> | |
157 | <hr /> | |
158 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> | |
159 | </DIV> | |
160 | <!--End of Navigation Panel--> | |
161 | <ADDRESS> | |
162 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. | |
163 | </ADDRESS> | |
164 | </BODY> | |
165 | </HTML> |