Name
select
Synopsis
select(inputs,outputs,excepts,timeout=None)
inputs,
outputs, and
excepts are lists of socket objects
waiting for input events, output events, and exceptional conditions,
respectively. timeout is a float, the
maximum time to wait in seconds. When
timeout is None, there
is no maximum wait: select waits until one or more
objects receive events. When timeout is
0, select returns at once,
without waiting.
select returns a tuple with three items
(
i,o,e
).
i is a list of zero or more of the items
of inputs, those that received input
events. o is a list of zero or more of the
items of outputs, those that received
output events. e is a list of zero or more
of the items of excepts, those that
received exceptional conditions (i.e., out-of-band data). Any or all
of i, o, and
e can be empty, but at least one of them
is non-empty if timeout is
None.
In addition to sockets, you can have in lists
inputs,
outputs, and
excepts other objects that supply a method
fileno, callable without arguments, returning a
socket’s file descriptor. For example, the server
classes of module SocketServer, covered earlier in
this chapter, follow this protocol. Therefore, you can have instances
of those classes in the lists. On Unix-like platforms,
select.select has wider applicability, since it
can also accept file descriptors that do not refer to sockets. On
Windows, however, select.select can accept only
file descriptors that do refer to sockets.
Example 19-6 uses module select to reimplement ...