【select模块】select IO多路复用和select实现FTP
select是全平臺通用的IO多路復(fù)用模塊。最大連接數(shù):1024。
poll和epoll沒有最大連接數(shù)限制,但只能用在linux平臺。
selectors是再封裝模塊,推薦使用。下篇會討論。
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 named fileno() returning such an integer:
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 by open() or os.popen()), socket objects returned by socket.socket(). ?You may also define a wrapper class yourself, as long as it
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)
| 方法、屬性 | 參數(shù) | 作用 | 示例 |
| select(rlist,wlist,rlist,[timout=1]) | |||
| poll() | 沒人用了,已經(jīng)升級為epoll | ||
| epoll(sizehint = -1,flags=0) | sizehint informs epoll about the expected number of events to be registered. ?It must be positive, or-1to use the default. It is only used on older systems where epoll_create1() is not available; otherwise it has no effect (though its value is still checked). flags is deprecated and completely ignored. ?However, when supplied, its value must be 0 or select.EPOLL_CLOEXEC, otherwise OSError is raised. | (Only supported on Linux 2.5.44 and newer.) Return an edge polling object, which can be used as Edge or Level Triggered interface for I/O events. | |
| devpoll() | ? | (Only supported on Solaris and derivatives.) ?Returns a /dev/poll polling object; see section /dev/poll Polling Objects below for the methods supported by devpoll objects. | |
| kevent() | select.kevent(ident, filter=KQ_FILTER_READ, flags=KQ_EV_ADD, fflags=0, data=0, udata=0)?
| ||
| kqueue() | (Only supported on BSD.) ?Returns a kernel queue object; see section Kqueue Objects below for the methods supported by kqueue objects. |
?
轉(zhuǎn)載于:https://blog.51cto.com/yishi/2150318
總結(jié)
以上是生活随笔為你收集整理的【select模块】select IO多路复用和select实现FTP的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 字符串右移n位
- 下一篇: 【大数据24小时】“天智一号”卫星将在太