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