blob: b8dfacc76eb88e633053ac6ab216ef19e5742a07 [file] [log] [blame]
Fred Drake3a0351c1998-04-04 07:23:21 +00001\section{Built-in Module \module{select}}
Fred Drakeb91e9341998-07-23 17:59:49 +00002\declaremodule{builtin}{select}
3
4\modulesynopsis{Wait for I/O completion on multiple streams.}
5
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00006
Fred Drakeb4016371998-04-02 18:44:38 +00007This module provides access to the function \cfunction{select()}
8available in most \UNIX{} versions. It defines the following:
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00009
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000010\begin{excdesc}{error}
11The exception raised when an error occurs. The accompanying value is
Fred Drakeb4016371998-04-02 18:44:38 +000012a pair containing the numeric error code from \cdata{errno} and the
13corresponding string, as would be printed by the \C{} function
14\cfunction{perror()}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000015\end{excdesc}
16
Fred Drakecce10901998-03-17 06:33:25 +000017\begin{funcdesc}{select}{iwtd, owtd, ewtd\optional{, timeout}}
Fred Drakeb4016371998-04-02 18:44:38 +000018This is a straightforward interface to the \UNIX{} \cfunction{select()}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000019system call. The first three arguments are lists of `waitable
20objects': either integers representing \UNIX{} file descriptors or
Fred Drakeb4016371998-04-02 18:44:38 +000021objects with a parameterless method named \method{fileno()} returning
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000022such an integer. The three lists of waitable objects are for input,
23output and `exceptional conditions', respectively. Empty lists are
Guido van Rossum02ee80d1995-04-04 12:29:37 +000024allowed. The optional \var{timeout} argument specifies a time-out as a
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000025floating point number in seconds. When the \var{timeout} argument
26is omitted the function blocks until at least one file descriptor is
27ready. A time-out value of zero specifies a poll and never blocks.
28
29The return value is a triple of lists of objects that are ready:
30subsets of the first three arguments. When the time-out is reached
31without a file descriptor becoming ready, three empty lists are
32returned.
33
34Amongst the acceptable object types in the lists are Python file
Fred Drakeb4016371998-04-02 18:44:38 +000035objects (e.g. \code{sys.stdin}, or objects returned by
36\function{open()} or \function{os.popen()}), socket objects
37returned by \function{socket.socket()},%
38\withsubitem{(in module socket)}{\ttindex{socket()}}
39\withsubitem{(in module posix)}{\ttindex{popen()}}
40\withsubitem{(in module os)}{\ttindex{popen()}}
41and the module \module{stdwin}\refbimodindex{stdwin} which happens to
42define a function \function{fileno()}%
43\withsubitem{(in module stdwin)}{\ttindex{fileno()}}
44for just this purpose. You may
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000045also define a \dfn{wrapper} class yourself, as long as it has an
Fred Drakeb4016371998-04-02 18:44:38 +000046appropriate \method{fileno()} method (that really returns a \UNIX{}
47file descriptor, not just a random integer).
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000048\end{funcdesc}