blob: 956bf7f3c0de9067d25410ffebc7013c79e38717 [file] [log] [blame]
Guido van Rossum470be141995-03-17 16:07:09 +00001\section{Built-in Module \sectcode{select}}
Guido van Rossume47da0a1997-07-17 16:34:52 +00002\label{module-select}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00003\bimodindex{select}
4
5This module provides access to the function \code{select} available in
6most \UNIX{} versions. It defines the following:
7
Fred Drake19479911998-02-13 06:58:54 +00008\setindexsubitem{(in module select)}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00009\begin{excdesc}{error}
10The exception raised when an error occurs. The accompanying value is
11a pair containing the numeric error code from \code{errno} and the
12corresponding string, as would be printed by the C function
13\code{perror()}.
14\end{excdesc}
15
Guido van Rossum02ee80d1995-04-04 12:29:37 +000016\begin{funcdesc}{select}{iwtd\, owtd\, ewtd\optional{\, timeout}}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000017This is a straightforward interface to the \UNIX{} \code{select()}
18system call. The first three arguments are lists of `waitable
19objects': either integers representing \UNIX{} file descriptors or
20objects with a parameterless method named \code{fileno()} returning
21such an integer. The three lists of waitable objects are for input,
22output and `exceptional conditions', respectively. Empty lists are
Guido van Rossum02ee80d1995-04-04 12:29:37 +000023allowed. The optional \var{timeout} argument specifies a time-out as a
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000024floating point number in seconds. When the \var{timeout} argument
25is omitted the function blocks until at least one file descriptor is
26ready. A time-out value of zero specifies a poll and never blocks.
27
28The return value is a triple of lists of objects that are ready:
29subsets of the first three arguments. When the time-out is reached
30without a file descriptor becoming ready, three empty lists are
31returned.
32
33Amongst the acceptable object types in the lists are Python file
34objects (e.g. \code{sys.stdin}, or objects returned by \code{open()}
35or \code{posix.popen()}), socket objects returned by
36\code{socket.socket()}, and the module \code{stdwin} which happens to
37define a function \code{fileno()} for just this purpose. You may
38also define a \dfn{wrapper} class yourself, as long as it has an
39appropriate \code{fileno()} method (that really returns a \UNIX{} file
40descriptor, not just a random integer).
41\end{funcdesc}
42\ttindex{socket}
43\ttindex{stdwin}