The poll() system call, supported on most Unix systems, provides better scalability for network servers that service many, many clients at the same time. poll() scales better because the system call only requires listing the file descriptors of interest, while select() builds a bitmap, turns on bits for the fds of interest, and then afterward the whole bitmap has to be linearly scanned again. select() is O(highest file descriptor), while poll() is O(number of file descriptors).
eventmask is an optional bitmask describing the type of events you want to check for, and can be a combination of the constants POLLIN, POLLPRI, and POLLOUT, described in the table below. If not specified, the default value used will check for all 3 types of events.
|POLLIN||There is data to read|
|POLLPRI||There is urgent data to read|
|POLLOUT||Ready for output: writing will not block|
|POLLERR||Error condition of some sort|
|POLLNVAL||Invalid request: descriptor not open|
Registering a file descriptor that's already registered is not an error, and has the same effect as registering the descriptor exactly once.
Attempting to remove a file descriptor that was never registered causes a KeyError exception to be raised.
(fd, event)2-tuples for the descriptors that have events or errors to report. fd is the file descriptor, and event is a bitmask with bits set for the reported events for that descriptor -- POLLIN for waiting input, POLLOUT to indicate that the descriptor can be written to, and so forth. An empty list indicates that the call timed out and no file descriptors had any events to report. If timeout is given, it specifies the length of time in milliseconds which the system will wait for events before returning. If timeout is omitted, negative, or
None, the call will block until there is an event for this poll object.
See About this document... for information on suggesting changes.