blob: 23b8b8dc786d38fb662125a38a207fadec595bf7 [file] [log] [blame]
Fred Drake295da241998-08-10 19:42:37 +00001\section{\module{select} ---
Fred Drakebbac4321999-02-20 00:14:17 +00002 Waiting for I/O completion}
Fred Drakeb91e9341998-07-23 17:59:49 +00003
Fred Drakebbac4321999-02-20 00:14:17 +00004\declaremodule{builtin}{select}
Fred Drakeb91e9341998-07-23 17:59:49 +00005\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()}
Guido van Rossum9814a941998-09-28 14:28:38 +00009available in most operating systems. Note that on Windows, it only
10works for sockets; on other operating systems, it also works for other
11file types (in particular, on \UNIX{}, it works on pipes). It cannot
12be used or regular files to determine whether a file has grown since
13it was last read.
14
15The module defines the following:
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000016
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000017\begin{excdesc}{error}
18The exception raised when an error occurs. The accompanying value is
Fred Drakeb4016371998-04-02 18:44:38 +000019a pair containing the numeric error code from \cdata{errno} and the
20corresponding string, as would be printed by the \C{} function
21\cfunction{perror()}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000022\end{excdesc}
23
Fred Drakecce10901998-03-17 06:33:25 +000024\begin{funcdesc}{select}{iwtd, owtd, ewtd\optional{, timeout}}
Fred Drakeb4016371998-04-02 18:44:38 +000025This is a straightforward interface to the \UNIX{} \cfunction{select()}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000026system call. The first three arguments are lists of `waitable
27objects': either integers representing \UNIX{} file descriptors or
Fred Drakeb4016371998-04-02 18:44:38 +000028objects with a parameterless method named \method{fileno()} returning
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000029such an integer. The three lists of waitable objects are for input,
30output and `exceptional conditions', respectively. Empty lists are
Guido van Rossum02ee80d1995-04-04 12:29:37 +000031allowed. The optional \var{timeout} argument specifies a time-out as a
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000032floating point number in seconds. When the \var{timeout} argument
33is omitted the function blocks until at least one file descriptor is
34ready. A time-out value of zero specifies a poll and never blocks.
35
36The return value is a triple of lists of objects that are ready:
37subsets of the first three arguments. When the time-out is reached
38without a file descriptor becoming ready, three empty lists are
39returned.
40
41Amongst the acceptable object types in the lists are Python file
Fred Drakeb4016371998-04-02 18:44:38 +000042objects (e.g. \code{sys.stdin}, or objects returned by
43\function{open()} or \function{os.popen()}), socket objects
44returned by \function{socket.socket()},%
45\withsubitem{(in module socket)}{\ttindex{socket()}}
Fred Drakeb4016371998-04-02 18:44:38 +000046\withsubitem{(in module os)}{\ttindex{popen()}}
47and the module \module{stdwin}\refbimodindex{stdwin} which happens to
Fred Drake283c5881999-04-21 17:57:15 +000048define a function
49\function{fileno()}\withsubitem{(in module stdwin)}{\ttindex{fileno()}}
Fred Drakeb4016371998-04-02 18:44:38 +000050for just this purpose. You may
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000051also define a \dfn{wrapper} class yourself, as long as it has an
Fred Drakeb4016371998-04-02 18:44:38 +000052appropriate \method{fileno()} method (that really returns a \UNIX{}
53file descriptor, not just a random integer).
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000054\end{funcdesc}