本文整理汇总了Python中select.POLLOUT属性的典型用法代码示例。如果您正苦于以下问题:Python select.POLLOUT属性的具体用法?Python select.POLLOUT怎么用?Python select.POLLOUT使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类select
的用法示例。
在下文中一共展示了select.POLLOUT属性的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _parse_events
# 需要导入模块: import select [as 别名]
# 或者: from select import POLLOUT [as 别名]
def _parse_events(self, events):
"""Parse ``events``.
``events`` is a list of events as returned by
:meth:`select.poll.poll()`.
Yield all parsed events.
"""
for fd, event_mask in events:
if self._has_event(event_mask, select.POLLNVAL):
raise IOError('File descriptor not open: {0!r}'.format(fd))
elif self._has_event(event_mask, select.POLLERR):
raise IOError('Error while polling fd: {0!r}'.format(fd))
if self._has_event(event_mask, select.POLLIN):
yield fd, 'r'
if self._has_event(event_mask, select.POLLOUT):
yield fd, 'w'
if self._has_event(event_mask, select.POLLHUP):
yield fd, 'h'
示例2: poll_wait_for_socket
# 需要导入模块: import select [as 别名]
# 或者: from select import POLLOUT [as 别名]
def poll_wait_for_socket(sock, read=False, write=False, timeout=None):
if not read and not write:
raise RuntimeError("must specify at least one of read=True, write=True")
mask = 0
if read:
mask |= select.POLLIN
if write:
mask |= select.POLLOUT
poll_obj = select.poll()
poll_obj.register(sock, mask)
# For some reason, poll() takes timeout in milliseconds
def do_poll(t):
if t is not None:
t *= 1000
return poll_obj.poll(t)
return bool(_retry_on_intr(do_poll, timeout))
示例3: select
# 需要导入模块: import select [as 别名]
# 或者: from select import POLLOUT [as 别名]
def select(self, timeout=None):
if timeout is None:
timeout = None
elif timeout <= 0:
timeout = 0
else:
# poll() has a resolution of 1 millisecond, round away from
# zero to wait *at least* timeout seconds.
timeout = int(math.ceil(timeout * 1e3))
ready = []
try:
fd_event_list = wrap_error(self._poll.poll, timeout)
except InterruptedError:
return ready
for fd, event in fd_event_list:
events = 0
if event & ~select.POLLIN:
events |= EVENT_WRITE
if event & ~select.POLLOUT:
events |= EVENT_READ
key = self._key_from_fd(fd)
if key:
ready.append((key, events & key.events))
return ready
示例4: pollmask_to_str
# 需要导入模块: import select [as 别名]
# 或者: from select import POLLOUT [as 别名]
def pollmask_to_str(mask):
"""
Conver pool mast to string
:param mask: poll return mask
"""
out = ""
if (mask & select.POLLIN):
out += "IN "
if (mask & select.POLLPRI):
out += "PRI IN "
if (mask & select.POLLOUT):
out += "OUT "
if (mask & select.POLLERR):
out += "ERR "
if (mask & select.POLLHUP):
out += "HUP "
if (mask & select.POLLMSG):
out += "MSG "
return out
示例5: poll
# 需要导入模块: import select [as 别名]
# 或者: from select import POLLOUT [as 别名]
def poll(self):
r, w, x = select.select(self.readable(), self.writable(), self.exceptional())
events = {}
self.collate_events(r, select.POLLIN, events)
self.collate_events(w, select.POLLOUT, events)
self.collate_events(x, select.POLLPRI, events)
final_events = []
for fd in events:
mask = 0
for event in events[fd]:
mask |= event
final_events.append([ fd, mask ])
return final_events
示例6: register
# 需要导入模块: import select [as 别名]
# 或者: from select import POLLOUT [as 别名]
def register(self, fileobj, events, data=None):
key = super(PollSelector, self).register(fileobj, events, data)
event_mask = 0
if events & EVENT_READ:
event_mask |= select.POLLIN
if events & EVENT_WRITE:
event_mask |= select.POLLOUT
self._poll.register(key.fd, event_mask)
return key
示例7: select
# 需要导入模块: import select [as 别名]
# 或者: from select import POLLOUT [as 别名]
def select(self, timeout=None):
ready = []
fd_events = _syscall_wrapper(self._wrap_poll, True, timeout=timeout)
for fd, event_mask in fd_events:
events = 0
if event_mask & ~select.POLLIN:
events |= EVENT_WRITE
if event_mask & ~select.POLLOUT:
events |= EVENT_READ
key = self._key_from_fd(fd)
if key:
ready.append((key, events & key.events))
return ready