<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!--Converted with LaTeX2HTML 98.2 beta6 (August 14th, 1998)
original version by:  Nikos Drakos, CBLU, University of Leeds
* revised and updated by:  Marcus Hennecke, Ross Moore, Herb Swan
* with significant contributions from:
  Jens Lippmann, Marek Rouchal, Martin Wilck and others -->
<HTML>
<HEAD>
<TITLE>7.3 select --
Waiting for I/O completion</TITLE>
<META NAME="description" CONTENT="7.3 select --
Waiting for I/O completion">
<META NAME="keywords" CONTENT="lib">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<LINK REL="STYLESHEET" HREF="lib.css">
<LINK REL="next" HREF="module-thread.html">
<LINK REL="previous" HREF="module-socket.html">
<LINK REL="up" HREF="someos.html">
<LINK REL="next" HREF="module-thread.html">
</HEAD>
<BODY bgcolor="#ffffff">
<div class=navigation>
<table align=center width="100%" cellpadding=0 cellspacing=2>
<tr>
<td><A HREF="module-thread.html"><img width=32 height=32 align=bottom border=0 alt="next"
 src="../icons/next.gif"></A></td>
<td><A HREF="someos.html"><img width=32 height=32 align=bottom border=0 alt="up"
 src="../icons/up.gif"></A></td>
<td><A HREF="Socket_Example.html"><img width=32 height=32 align=bottom border=0 alt="previous"
 src="../icons/previous.gif"></A></td>
<td align=center bgcolor="#99CCFF" width="100%">
 <b class=title>Python Library Reference</b></td>
<td><A HREF="contents.html"><img width=32 height=32 align=bottom border=0 alt="contents"
 src="../icons/contents.gif"></A></td>
<td><a
 href="modindex.html"><img width=32 height=32 align=bottom border=0 alt="modules"
 src="../icons/modules.gif"></a></td>
<td><A HREF="genindex.html"><img width=32 height=32 align=bottom border=0 alt="index"
 src="../icons/index.gif"></A></td>
</tr></table><b class=navlabel>Next:</b> <span class=sectref><A HREF="module-thread.html">7.4 thread  </A></span>
<b class=navlabel>Up:</b> <span class=sectref><A HREF="someos.html">7. Optional Operating System</A></span>
<b class=navlabel>Previous:</b> <span class=sectref><A HREF="Socket_Example.html">7.2.2 Example</A></span>
<br><hr></div>
<!--End of Navigation Panel-->

<H1><A NAME="SECTION009300000000000000000">
7.3 <tt class=module>select</tt> --
         Waiting for I/O completion</A>
</H1>

<P>


<P>
This module provides access to the function <tt class=cfunction>select()</tt>
available in most operating systems.  Note that on Windows, it only
works for sockets; on other operating systems, it also works for other
file types (in particular, on Unix, it works on pipes).  It cannot
be used or regular files to determine whether a file has grown since
it was last read.

<P>
The module defines the following:

<P>
<dl><dt><b><a name="l2h-1310"><tt class=exception>error</tt></a></b>
<dd>
The exception raised when an error occurs.  The accompanying value is
a pair containing the numeric error code from <tt class=cdata>errno</tt> and the
corresponding string, as would be printed by the C function
<tt class=cfunction>perror()</tt>.
</dl>

<P>
<dl><dt><b><a name="l2h-1311"><tt class=function>select</tt></a></b> (<var>iwtd, owtd, ewtd</var><big>[</big><var>, timeout</var><big>]</big>)
<dd>
This is a straightforward interface to the Unix <tt class=cfunction>select()</tt>
system call.  The first three arguments are lists of `waitable
objects': either integers representing Unix file descriptors or
objects with a parameterless method named <tt class=method>fileno()</tt> returning
such an integer.  The three lists of waitable objects are for input,
output and `exceptional conditions', respectively.  Empty lists are
allowed.  The optional <var>timeout</var> argument specifies a time-out as a
floating point number in seconds.  When the <var>timeout</var> argument
is omitted the function blocks until at least one file descriptor is
ready.  A time-out value of zero specifies a poll and never blocks.

<P>
The return value is a triple of lists of objects that are ready:
subsets of the first three arguments.  When the time-out is reached
without a file descriptor becoming ready, three empty lists are
returned.

<P>
Amongst the acceptable object types in the lists are Python file
objects (e.g. <tt>sys.stdin</tt>, or objects returned by
<tt class=function>open()</tt> or <tt class=function>os.popen()</tt>), socket objects
returned by <tt class=function>socket.socket()</tt>,<a name="l2h-1313"></a><a name="l2h-1315"></a>and the module <tt class=module>stdwin</tt><a name="l2h-1318"></a> which happens to
define a function
<tt class=function>fileno()</tt><a name="l2h-1317"></a>for just this purpose.  You may
also define a <i class=dfn>wrapper</i> class yourself, as long as it has an
appropriate <tt class=method>fileno()</tt> method (that really returns a Unix
file descriptor, not just a random integer).
</dl><p>
<div class=navigation><hr><table align=center width="100%" cellpadding=0 cellspacing=2>
<tr>
<td><A HREF="module-thread.html"><img width=32 height=32 align=bottom border=0 alt="next"
 src="../icons/next.gif"></A></td>
<td><A HREF="someos.html"><img width=32 height=32 align=bottom border=0 alt="up"
 src="../icons/up.gif"></A></td>
<td><A HREF="Socket_Example.html"><img width=32 height=32 align=bottom border=0 alt="previous"
 src="../icons/previous.gif"></A></td>
<td align=center bgcolor="#99CCFF" width="100%">
 <b class=title>Python Library Reference</b></td>
<td><A HREF="contents.html"><img width=32 height=32 align=bottom border=0 alt="contents"
 src="../icons/contents.gif"></A></td>
<td><a
 href="modindex.html"><img width=32 height=32 align=bottom border=0 alt="modules"
 src="../icons/modules.gif"></a></td>
<td><A HREF="genindex.html"><img width=32 height=32 align=bottom border=0 alt="index"
 src="../icons/index.gif"></A></td>
</tr></table><b class=navlabel>Next:</b> <span class=sectref><A HREF="module-thread.html">7.4 thread  </A></span>
<b class=navlabel>Up:</b> <span class=sectref><A HREF="someos.html">7. Optional Operating System</A></span>
<b class=navlabel>Previous:</b> <span class=sectref><A HREF="Socket_Example.html">7.2.2 Example</A></span>
</div>
<!--End of Navigation Panel-->
<ADDRESS>
<hr>Send comments on this document to <a href="mailto:python-docs@python.org">python-docs@python.org</a>.
</ADDRESS>
</BODY>
</HTML>
