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