本文整理汇总了Python中select.KQ_FILTER_WRITE属性的典型用法代码示例。如果您正苦于以下问题:Python select.KQ_FILTER_WRITE属性的具体用法?Python select.KQ_FILTER_WRITE怎么用?Python select.KQ_FILTER_WRITE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类select
的用法示例。
在下文中一共展示了select.KQ_FILTER_WRITE属性的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: poll
# 需要导入模块: import select [as 别名]
# 或者: from select import KQ_FILTER_WRITE [as 别名]
def poll(self, timeout):
kevents = self._kqueue.control(None, 1000, timeout)
events = {}
for kevent in kevents:
fd = kevent.ident
if kevent.filter == select.KQ_FILTER_READ:
events[fd] = events.get(fd, 0) | IOLoop.READ
if kevent.filter == select.KQ_FILTER_WRITE:
if kevent.flags & select.KQ_EV_EOF:
# If an asynchronous connection is refused, kqueue
# returns a write event with the EOF flag set.
# Turn this into an error for consistency with the
# other IOLoop implementations.
# Note that for read events, EOF may be returned before
# all data has been consumed from the socket buffer,
# so we only check for EOF on write events.
events[fd] = IOLoop.ERROR
else:
events[fd] = events.get(fd, 0) | IOLoop.WRITE
if kevent.flags & select.KQ_EV_ERROR:
events[fd] = events.get(fd, 0) | IOLoop.ERROR
return events.items()
示例2: register
# 需要导入模块: import select [as 别名]
# 或者: from select import KQ_FILTER_WRITE [as 别名]
def register(self, fileobj, events, data=None):
key = super(KqueueSelector, self).register(fileobj, events, data)
if events & EVENT_READ:
kevent = select.kevent(key.fd,
select.KQ_FILTER_READ,
select.KQ_EV_ADD)
_syscall_wrapper(self._kqueue.control, False, [kevent], 0, 0)
if events & EVENT_WRITE:
kevent = select.kevent(key.fd,
select.KQ_FILTER_WRITE,
select.KQ_EV_ADD)
_syscall_wrapper(self._kqueue.control, False, [kevent], 0, 0)
return key
示例3: unregister
# 需要导入模块: import select [as 别名]
# 或者: from select import KQ_FILTER_WRITE [as 别名]
def unregister(self, fileobj):
key = super(KqueueSelector, self).unregister(fileobj)
if key.events & EVENT_READ:
kevent = select.kevent(key.fd,
select.KQ_FILTER_READ,
select.KQ_EV_DELETE)
try:
_syscall_wrapper(self._kqueue.control, False, [kevent], 0, 0)
except SelectorError:
pass
if key.events & EVENT_WRITE:
kevent = select.kevent(key.fd,
select.KQ_FILTER_WRITE,
select.KQ_EV_DELETE)
try:
_syscall_wrapper(self._kqueue.control, False, [kevent], 0, 0)
except SelectorError:
pass
return key
示例4: unregister
# 需要导入模块: import select [as 别名]
# 或者: from select import KQ_FILTER_WRITE [as 别名]
def unregister(self, fileobj):
key = super(KqueueSelector, self).unregister(fileobj)
if key.events & EVENT_READ:
kev = select.kevent(key.fd, select.KQ_FILTER_READ,
select.KQ_EV_DELETE)
try:
self._kqueue.control([kev], 0, 0)
except OSError:
# This can happen if the FD was closed since it
# was registered.
pass
if key.events & EVENT_WRITE:
kev = select.kevent(key.fd, select.KQ_FILTER_WRITE,
select.KQ_EV_DELETE)
try:
self._kqueue.control([kev], 0, 0)
except OSError:
# See comment above.
pass
return key
示例5: select
# 需要导入模块: import select [as 别名]
# 或者: from select import KQ_FILTER_WRITE [as 别名]
def select(self, timeout=None):
timeout = None if timeout is None else max(timeout, 0)
max_ev = len(self._fd_to_key)
ready = []
try:
kev_list = wrap_error(self._kqueue.control,
None, max_ev, timeout)
except InterruptedError:
return ready
for kev in kev_list:
fd = kev.ident
flag = kev.filter
events = 0
if flag == select.KQ_FILTER_READ:
events |= EVENT_READ
if flag == select.KQ_FILTER_WRITE:
events |= EVENT_WRITE
key = self._key_from_fd(fd)
if key:
ready.append((key, events & key.events))
return ready
示例6: poll
# 需要导入模块: import select [as 别名]
# 或者: from select import KQ_FILTER_WRITE [as 别名]
def poll(self, timeout=None):
events = self.kqueue.control(self.events, 128, timeout)
rv = []
for ev in events:
obj = self.event_to_object.get(ev.ident)
if obj is None:
# It happens surprisingly frequently that kqueue returns
# write events things no longer in the kqueue. Not sure
# why
continue
if ev.filter == select.KQ_FILTER_READ:
rv.append((obj, 'read'))
elif ev.filter == select.KQ_FILTER_WRITE:
rv.append((obj, 'write'))
if ev.flags & select.KQ_EV_EOF:
rv.append((obj, 'close'))
return rv
示例7: _control
# 需要导入模块: import select [as 别名]
# 或者: from select import KQ_FILTER_WRITE [as 别名]
def _control(self, fd, events, flags):
kevents = []
if events & self.WRITE:
kevents.append(select.kevent(
fd, filter=select.KQ_FILTER_WRITE, flags=flags))
if events & self.READ or not kevents:
# always read when there is not a write
kevents.append(select.kevent(
fd, filter=select.KQ_FILTER_READ, flags=flags))
# even though control() takes a list, it seems to return
# EINVAL on Mac OS X (10.6) when there is more than one
# event in the list
for kevent in kevents:
self._kqueue.control([kevent], 0)
# localize variable access to minimize overhead