Fred Drake | 295da24 | 1998-08-10 19:42:37 +0000 | [diff] [blame] | 1 | \section{\module{select} --- |
Fred Drake | bbac432 | 1999-02-20 00:14:17 +0000 | [diff] [blame] | 2 | Waiting for I/O completion} |
Fred Drake | b91e934 | 1998-07-23 17:59:49 +0000 | [diff] [blame] | 3 | |
Fred Drake | bbac432 | 1999-02-20 00:14:17 +0000 | [diff] [blame] | 4 | \declaremodule{builtin}{select} |
Fred Drake | b91e934 | 1998-07-23 17:59:49 +0000 | [diff] [blame] | 5 | \modulesynopsis{Wait for I/O completion on multiple streams.} |
| 6 | |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 7 | |
Fred Drake | b401637 | 1998-04-02 18:44:38 +0000 | [diff] [blame] | 8 | This module provides access to the function \cfunction{select()} |
Guido van Rossum | 9814a94 | 1998-09-28 14:28:38 +0000 | [diff] [blame] | 9 | available in most operating systems. Note that on Windows, it only |
| 10 | works for sockets; on other operating systems, it also works for other |
| 11 | file types (in particular, on \UNIX{}, it works on pipes). It cannot |
| 12 | be used or regular files to determine whether a file has grown since |
| 13 | it was last read. |
| 14 | |
| 15 | The module defines the following: |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 16 | |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 17 | \begin{excdesc}{error} |
| 18 | The exception raised when an error occurs. The accompanying value is |
Fred Drake | b401637 | 1998-04-02 18:44:38 +0000 | [diff] [blame] | 19 | a pair containing the numeric error code from \cdata{errno} and the |
| 20 | corresponding string, as would be printed by the \C{} function |
| 21 | \cfunction{perror()}. |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 22 | \end{excdesc} |
| 23 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 24 | \begin{funcdesc}{select}{iwtd, owtd, ewtd\optional{, timeout}} |
Fred Drake | b401637 | 1998-04-02 18:44:38 +0000 | [diff] [blame] | 25 | This is a straightforward interface to the \UNIX{} \cfunction{select()} |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 26 | system call. The first three arguments are lists of `waitable |
| 27 | objects': either integers representing \UNIX{} file descriptors or |
Fred Drake | b401637 | 1998-04-02 18:44:38 +0000 | [diff] [blame] | 28 | objects with a parameterless method named \method{fileno()} returning |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 29 | such an integer. The three lists of waitable objects are for input, |
| 30 | output and `exceptional conditions', respectively. Empty lists are |
Guido van Rossum | 02ee80d | 1995-04-04 12:29:37 +0000 | [diff] [blame] | 31 | 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] | 32 | floating point number in seconds. When the \var{timeout} argument |
| 33 | is omitted the function blocks until at least one file descriptor is |
| 34 | ready. A time-out value of zero specifies a poll and never blocks. |
| 35 | |
| 36 | The return value is a triple of lists of objects that are ready: |
| 37 | subsets of the first three arguments. When the time-out is reached |
| 38 | without a file descriptor becoming ready, three empty lists are |
| 39 | returned. |
| 40 | |
| 41 | Amongst the acceptable object types in the lists are Python file |
Fred Drake | b401637 | 1998-04-02 18:44:38 +0000 | [diff] [blame] | 42 | objects (e.g. \code{sys.stdin}, or objects returned by |
| 43 | \function{open()} or \function{os.popen()}), socket objects |
| 44 | returned by \function{socket.socket()},% |
| 45 | \withsubitem{(in module socket)}{\ttindex{socket()}} |
Fred Drake | b401637 | 1998-04-02 18:44:38 +0000 | [diff] [blame] | 46 | \withsubitem{(in module os)}{\ttindex{popen()}} |
| 47 | and the module \module{stdwin}\refbimodindex{stdwin} which happens to |
Fred Drake | 283c588 | 1999-04-21 17:57:15 +0000 | [diff] [blame] | 48 | define a function |
| 49 | \function{fileno()}\withsubitem{(in module stdwin)}{\ttindex{fileno()}} |
Fred Drake | b401637 | 1998-04-02 18:44:38 +0000 | [diff] [blame] | 50 | for just this purpose. You may |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 51 | also define a \dfn{wrapper} class yourself, as long as it has an |
Fred Drake | b401637 | 1998-04-02 18:44:38 +0000 | [diff] [blame] | 52 | appropriate \method{fileno()} method (that really returns a \UNIX{} |
| 53 | file descriptor, not just a random integer). |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 54 | \end{funcdesc} |