本文整理匯總了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