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