This module provides access to the select()
and poll()
functions available in most operating systems, epoll()
available on Linux 2.5+ and kqueue()
available on most BSD. 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 be used on regular files to determine whether a file has grown since it was last read.
The module defines the following:
- exception
select.
error
The exception raised when an error occurs. The accompanying value is a pair containing the numeric error code from
errno
and the corresponding string, as would be printed by the C functionperror()
.
select.
epoll
([sizehint=-1])(Only supported on Linux 2.5.44 and newer.) Returns an edge polling object, which can be used as Edge or Level Triggered interface for I/O events; see section Edge and Level Trigger Polling (epoll) Objects below for the methods supported by epolling objects.
New in version 2.6.
select.
poll
()(Not supported by all operating systems.) Returns a polling object, which supports registering and unregistering file descriptors, and then polling them for I/O events; see section Polling Objects below for the methods supported by polling objects.
select.
kqueue
()(Only supported on BSD.) Returns a kernel queue object; see section Kqueue Objects below for the methods supported by kqueue objects.
New in version 2.6.
select.
kevent
(ident, filter=KQ_FILTER_READ, flags=KQ_EV_ADD, fflags=0, data=0, udata=0)(Only supported on BSD.) Returns a kernel event object; see section Kevent Objects below for the methods supported by kevent objects.
New in version 2.6.
select.
select
(rlist, wlist, xlist[, timeout])This is a straightforward interface to the Unix
select()
system call. The first three arguments are sequences of ‘waitable objects’: either integers representing file descriptors or objects with a parameterless method namedfileno()
returning such an integer:- rlist: wait until ready for reading
- wlist: wait until ready for writing
- xlist: wait for an “exceptional condition” (see the manual page for what your system considers such a condition)
Empty sequences are allowed, but acceptance of three empty sequences is platform-dependent. (It is known to work on Unix but not on Windows.) The optional timeout argument specifies a time-out as a floating point number in seconds. When the 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.
Among the acceptable object types in the sequences are Python file objects (e.g.
sys.stdin
, or objects returned byopen()
oros.popen()
), socket objects returned bysocket.socket()
. You may also define a wrapper class yourself, as long as it has an appropriatefileno()
method (that really returns a file descriptor, not just a random integer).Note
File objects on Windows are not acceptable, but sockets are. On Windows, the underlying
select()
function is provided by the WinSock library, and does not handle file descriptors that don’t originate from WinSock.
select.
PIPE_BUF
Files reported as ready for writing by
select()
,poll()
or similar interfaces in this module are guaranteed to not block on a write of up toPIPE_BUF
bytes. This value is guaranteed by POSIX to be at least 512. Availability: Unix.New in version 2.7.
'개발 저장소 > Python&Django' 카테고리의 다른 글
파이썬 함수 사용 모음 (1079) | 2016.07.04 |
---|---|
python- 파이썬 os.path 모듈 (252) | 2016.06.06 |
[3일차] Django 웹 프레임 워크 (281) | 2016.03.02 |
[2일차] 파이썬 웹 표준 라이브러리 (267) | 2016.03.02 |
[1일차] 웹프로그래밍의 이해 (251) | 2016.03.02 |
댓글