# encoding: utf-8
# module select
# from (pre-generated)
# by generator 1.145
"""
This module supports asynchronous I/O on multiple file descriptors.
*** IMPORTANT NOTICE ***
On Windows and OpenVMS, only sockets are supported; on Unix, all file descriptors.
"""
# no imports
# functions
def select(rlist, wlist, xlist, timeout=None): # real signature unknown; restored from __doc__
"""
select(rlist, wlist, xlist[, timeout]) -> (rlist, wlist, xlist)
Wait until one or more file descriptors are ready for some kind of I/O.
The first three arguments are sequences of file descriptors to be waited for:
rlist -- wait until ready for reading
wlist -- wait until ready for writing
xlist -- wait for an ``exceptional condition''
If only one kind of condition is required, pass [] for the other lists.
A file descriptor is either a socket or file object, or a small integer
gotten from a fileno() method call on one of those.
The optional 4th argument specifies a timeout in seconds; it may be
a floating point number to specify fractions of seconds. If it is absent
or None, the call will never time out.
The return value is a tuple of three lists corresponding to the first three
arguments; each contains the subset of the corresponding file descriptors
that are ready.
*** IMPORTANT NOTICE ***
On Windows and OpenVMS, only sockets are supported; on Unix, all file
descriptors can be used.
"""
pass
# classes
class error(Exception):
# no doc
def __init__(self, *args, **kwargs): # real signature unknown
pass
__weakref__ = property(lambda self: object(), lambda self, v: None, lambda self: None) # default
"""list of weak references to the object (if defined)"""
-
#select的原型为(rlist,wlist,xlist[,timeout]),
-
# 其中rlist是等待读取的对象,
-
# wlist是等待写入的对象,
-
# xlist是等待异常的对象,
-
rs,ws,es=select.select(inputs,[],[],1)
#1、select函数阻塞进程,直到inputs中的套接字被触发(在此例中,套接字接收到客户端发来的握手信号,从而变得可读,满足select函数的“可读”条件),rs返回被触发的套接字(服务器套接字);
redis websocket select结合推送消息
@get('/websocket', apply=[websocket]) def main(environ, start_response): channel = rd.pubsub() uid = environ.get('QUERY_STRING').split("=")[1] channel.subscribe(uid) rd_fd = channel.connection._sock.fileno() while True: data = select.select([rd_fd], [], [], 4.0) for fd in data[0]: if fd == rd_fd: msg = channel.parse_response() ws = environ["wsgi.websocket"] if msg[0] == 'message': ws.send(msg[2])