| 
									
										
										
										
											1998-08-10 19:42:37 +00:00
										 |  |  | \section{\module{select} --- | 
					
						
							| 
									
										
										
										
											1999-02-20 00:14:17 +00:00
										 |  |  |          Waiting for I/O completion} | 
					
						
							| 
									
										
										
										
											1998-07-23 17:59:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1999-02-20 00:14:17 +00:00
										 |  |  | \declaremodule{builtin}{select} | 
					
						
							| 
									
										
										
										
											1998-07-23 17:59:49 +00:00
										 |  |  | \modulesynopsis{Wait for I/O completion on multiple streams.} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1994-01-02 01:22:07 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-04-02 18:44:38 +00:00
										 |  |  | This module provides access to the function \cfunction{select()} | 
					
						
							| 
									
										
										
										
											1998-09-28 14:28:38 +00:00
										 |  |  | available in most operating systems.  Note that on Windows, it only | 
					
						
							|  |  |  | works for sockets; on other operating systems, it also works for other | 
					
						
							|  |  |  | file types (in particular, on \UNIX{}, it works on pipes).  It cannot | 
					
						
							| 
									
										
										
										
											2000-04-03 20:13:55 +00:00
										 |  |  | be used on regular files to determine whether a file has grown since | 
					
						
							| 
									
										
										
										
											1998-09-28 14:28:38 +00:00
										 |  |  | it was last read. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | The module defines the following: | 
					
						
							| 
									
										
										
										
											1994-01-02 01:22:07 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | \begin{excdesc}{error} | 
					
						
							|  |  |  | The exception raised when an error occurs.  The accompanying value is | 
					
						
							| 
									
										
										
										
											1998-04-02 18:44:38 +00:00
										 |  |  | a pair containing the numeric error code from \cdata{errno} and the | 
					
						
							|  |  |  | corresponding string, as would be printed by the \C{} function | 
					
						
							|  |  |  | \cfunction{perror()}. | 
					
						
							| 
									
										
										
										
											1994-01-02 01:22:07 +00:00
										 |  |  | \end{excdesc} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-03-17 06:33:25 +00:00
										 |  |  | \begin{funcdesc}{select}{iwtd, owtd, ewtd\optional{, timeout}} | 
					
						
							| 
									
										
										
										
											1998-04-02 18:44:38 +00:00
										 |  |  | This is a straightforward interface to the \UNIX{} \cfunction{select()} | 
					
						
							| 
									
										
										
										
											1994-01-02 01:22:07 +00:00
										 |  |  | system call.  The first three arguments are lists of `waitable | 
					
						
							|  |  |  | objects': either integers representing \UNIX{} file descriptors or | 
					
						
							| 
									
										
										
										
											1998-04-02 18:44:38 +00:00
										 |  |  | objects with a parameterless method named \method{fileno()} returning | 
					
						
							| 
									
										
										
										
											1994-01-02 01:22:07 +00:00
										 |  |  | such an integer.  The three lists of waitable objects are for input, | 
					
						
							|  |  |  | output and `exceptional conditions', respectively.  Empty lists are | 
					
						
							| 
									
										
										
										
											1995-04-04 12:29:37 +00:00
										 |  |  | allowed.  The optional \var{timeout} argument specifies a time-out as a | 
					
						
							| 
									
										
										
										
											1994-01-02 01:22:07 +00:00
										 |  |  | floating point number in seconds.  When the \var{timeout} argument | 
					
						
							|  |  |  | is omitted the function blocks until at least one file descriptor is | 
					
						
							|  |  |  | ready.  A time-out value of zero specifies a poll and never blocks. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | The return value is a triple of lists of objects that are ready: | 
					
						
							|  |  |  | subsets of the first three arguments.  When the time-out is reached | 
					
						
							|  |  |  | without a file descriptor becoming ready, three empty lists are | 
					
						
							|  |  |  | returned. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Amongst the acceptable object types in the lists are Python file | 
					
						
							| 
									
										
										
										
											1998-04-02 18:44:38 +00:00
										 |  |  | objects (e.g. \code{sys.stdin}, or objects returned by | 
					
						
							|  |  |  | \function{open()} or \function{os.popen()}), socket objects | 
					
						
							|  |  |  | returned by \function{socket.socket()},%
 | 
					
						
							|  |  |  | \withsubitem{(in module socket)}{\ttindex{socket()}} | 
					
						
							|  |  |  | \withsubitem{(in module os)}{\ttindex{popen()}} | 
					
						
							|  |  |  | and the module \module{stdwin}\refbimodindex{stdwin} which happens to | 
					
						
							| 
									
										
										
										
											1999-04-21 17:57:15 +00:00
										 |  |  | define a function | 
					
						
							|  |  |  | \function{fileno()}\withsubitem{(in module stdwin)}{\ttindex{fileno()}} | 
					
						
							| 
									
										
										
										
											1998-04-02 18:44:38 +00:00
										 |  |  | for just this purpose.  You may | 
					
						
							| 
									
										
										
										
											1994-01-02 01:22:07 +00:00
										 |  |  | also define a \dfn{wrapper} class yourself, as long as it has an | 
					
						
							| 
									
										
										
										
											1998-04-02 18:44:38 +00:00
										 |  |  | appropriate \method{fileno()} method (that really returns a \UNIX{} | 
					
						
							|  |  |  | file descriptor, not just a random integer). | 
					
						
							| 
									
										
										
										
											1994-01-02 01:22:07 +00:00
										 |  |  | \end{funcdesc} |