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