Commit | Line | Data |
---|---|---|
86530b38 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="module-thread.html" /> | |
13 | <link rel="prev" href="module-socket.html" /> | |
14 | <link rel="parent" href="someos.html" /> | |
15 | <link rel="next" href="poll-objects.html" /> | |
16 | <meta name='aesop' content='information' /> | |
17 | <title>7.3 select -- Waiting for I/O completion</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.2.3 Example" | |
25 | href="socket-example.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. Optional Operating System" | |
28 | href="someos.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.3.1 Polling Objects" | |
31 | href="poll-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="socket-example.html">7.2.3 Example</A> | |
46 | <b class="navlabel">Up:</b> | |
47 | <a class="sectref" rel="parent" href="someos.html">7. Optional Operating System</A> | |
48 | <b class="navlabel">Next:</b> | |
49 | <a class="sectref" rel="next" href="poll-objects.html">7.3.1 Polling Objects</A> | |
50 | </div> | |
51 | <hr /></div> | |
52 | </DIV> | |
53 | <!--End of Navigation Panel--> | |
54 | ||
55 | <H1><A NAME="SECTION009300000000000000000"> | |
56 | 7.3 <tt class="module">select</tt> -- | |
57 | Waiting for I/O completion</A> | |
58 | </H1> | |
59 | ||
60 | <P> | |
61 | <A NAME="module-select"></A> | |
62 | ||
63 | <P> | |
64 | This module provides access to the <tt class="cfunction">select()</tt> | |
65 | and <tt class="cfunction">poll()</tt> functions | |
66 | available in most operating systems. Note that on Windows, it only | |
67 | works for sockets; on other operating systems, it also works for other | |
68 | file types (in particular, on <span class="Unix">Unix</span>, it works on pipes). It cannot | |
69 | be used on regular files to determine whether a file has grown since | |
70 | it was last read. | |
71 | ||
72 | <P> | |
73 | The module defines the following: | |
74 | ||
75 | <P> | |
76 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-2676' xml:id='l2h-2676' class="exception">error</tt></b></dt> | |
77 | <dd> | |
78 | The exception raised when an error occurs. The accompanying value is | |
79 | a pair containing the numeric error code from <tt class="cdata">errno</tt> and the | |
80 | corresponding string, as would be printed by the C function | |
81 | <tt class="cfunction">perror()</tt>. | |
82 | </dd></dl> | |
83 | ||
84 | <P> | |
85 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
86 | <td><nobr><b><tt id='l2h-2677' xml:id='l2h-2677' class="function">poll</tt></b>(</nobr></td> | |
87 | <td><var></var>)</td></tr></table></dt> | |
88 | <dd> | |
89 | (Not supported by all operating systems.) Returns a polling object, | |
90 | which supports registering and unregistering file descriptors, and | |
91 | then polling them for I/O events; | |
92 | see section <A href="poll-objects.html#poll-objects">7.3.1</A> below for the methods supported by | |
93 | polling objects. | |
94 | </dl> | |
95 | ||
96 | <P> | |
97 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
98 | <td><nobr><b><tt id='l2h-2678' xml:id='l2h-2678' class="function">select</tt></b>(</nobr></td> | |
99 | <td><var>iwtd, owtd, ewtd</var><big>[</big><var>, timeout</var><big>]</big><var></var>)</td></tr></table></dt> | |
100 | <dd> | |
101 | This is a straightforward interface to the <span class="Unix">Unix</span> <tt class="cfunction">select()</tt> | |
102 | system call. The first three arguments are sequences of `waitable | |
103 | objects': either integers representing file descriptors or | |
104 | objects with a parameterless method named <tt class="method">fileno()</tt> returning | |
105 | such an integer. The three sequences of waitable objects are for input, | |
106 | output and `exceptional conditions', respectively. Empty sequences are | |
107 | allowed, but acceptance of three empty sequences is platform-dependent. | |
108 | (It is known to work on <span class="Unix">Unix</span> but not on Windows.) The optional | |
109 | <var>timeout</var> argument specifies a time-out as a floating point number | |
110 | in seconds. When the <var>timeout</var> argument is omitted the function | |
111 | blocks until at least one file descriptor is ready. A time-out value | |
112 | of zero specifies a poll and never blocks. | |
113 | ||
114 | <P> | |
115 | The return value is a triple of lists of objects that are ready: | |
116 | subsets of the first three arguments. When the time-out is reached | |
117 | without a file descriptor becoming ready, three empty lists are | |
118 | returned. | |
119 | ||
120 | <P> | |
121 | Among the acceptable object types in the sequences are Python file | |
122 | objects (e.g. <code>sys.stdin</code>, or objects returned by | |
123 | <tt class="function">open()</tt> or <tt class="function">os.popen()</tt>), socket objects | |
124 | returned by <tt class="function">socket.socket()</tt>.<a id='l2h-2680' xml:id='l2h-2680'></a><a id='l2h-2682' xml:id='l2h-2682'></a>You may also define a <i class="dfn">wrapper</i> class yourself, as long as it has | |
125 | an appropriate <tt class="method">fileno()</tt> method (that really returns a file | |
126 | descriptor, not just a random integer). | |
127 | <span class="note"><b class="label">Note:</b> | |
128 | File objects on Windows are not acceptable, but sockets | |
129 | are.<a id='l2h-2683' xml:id='l2h-2683'></a> On Windows, the underlying <tt class="cfunction">select()</tt> | |
130 | function is provided by the WinSock library, and does not handle file | |
131 | descriptors that don't originate from WinSock.</span> | |
132 | </dl> | |
133 | ||
134 | <P> | |
135 | ||
136 | <p><br /></p><hr class='online-navigation' /> | |
137 | <div class='online-navigation'> | |
138 | <!--Table of Child-Links--> | |
139 | <A NAME="CHILD_LINKS"><STRONG>Subsections</STRONG></a> | |
140 | ||
141 | <UL CLASS="ChildLinks"> | |
142 | <LI><A href="poll-objects.html">7.3.1 Polling Objects</a> | |
143 | </ul> | |
144 | <!--End of Table of Child-Links--> | |
145 | </div> | |
146 | ||
147 | <DIV CLASS="navigation"> | |
148 | <div class='online-navigation'> | |
149 | <p></p><hr /> | |
150 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
151 | <tr> | |
152 | <td class='online-navigation'><a rel="prev" title="7.2.3 Example" | |
153 | href="socket-example.html"><img src='../icons/previous.png' | |
154 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
155 | <td class='online-navigation'><a rel="parent" title="7. Optional Operating System" | |
156 | href="someos.html"><img src='../icons/up.png' | |
157 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
158 | <td class='online-navigation'><a rel="next" title="7.3.1 Polling Objects" | |
159 | href="poll-objects.html"><img src='../icons/next.png' | |
160 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
161 | <td align="center" width="100%">Python Library Reference</td> | |
162 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
163 | href="contents.html"><img src='../icons/contents.png' | |
164 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
165 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
166 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
167 | <td class='online-navigation'><a rel="index" title="Index" | |
168 | href="genindex.html"><img src='../icons/index.png' | |
169 | border='0' height='32' alt='Index' width='32' /></A></td> | |
170 | </tr></table> | |
171 | <div class='online-navigation'> | |
172 | <b class="navlabel">Previous:</b> | |
173 | <a class="sectref" rel="prev" href="socket-example.html">7.2.3 Example</A> | |
174 | <b class="navlabel">Up:</b> | |
175 | <a class="sectref" rel="parent" href="someos.html">7. Optional Operating System</A> | |
176 | <b class="navlabel">Next:</b> | |
177 | <a class="sectref" rel="next" href="poll-objects.html">7.3.1 Polling Objects</A> | |
178 | </div> | |
179 | </div> | |
180 | <hr /> | |
181 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> | |
182 | </DIV> | |
183 | <!--End of Navigation Panel--> | |
184 | <ADDRESS> | |
185 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. | |
186 | </ADDRESS> | |
187 | </BODY> | |
188 | </HTML> |