select – Wait for I/O Efficiently
Purpose: Wait for notification that an input or output channel is ready. Available In: 1.4 and later The module provides access to platform-specific I/O monitoring functions. The most portable interface is the POSIX function , which is available on Unix and Windows. The module also includes poll(), a Unix-only API, and several options that only work with specific variants of Unix.
select()
Python’s function is a direct interface to the underlying operating system implementation. It monitors sockets, open files, and pipes (anything with a fileno() method that returns a valid file descriptor) until they become readable or writable, or a communication error occurs. makes it easier to monitor multiple connections at the same time, and is more efficient than writing a polling loop in Python using socket timeouts, because the monitoring happens in the operating system network layer, instead of the interpreter.
Note
Using Python’s file objects with works for Unix, but is not supported under Windows.
The echo server example from the section can be extended to watch for more than one connection at a time by using . The new version starts out by creating a non-blocking TCP/IP socket and configuring it to listen on an address.