本文整理匯總了Python中select.KQ_EV_ENABLE屬性的典型用法代碼示例。如果您正苦於以下問題:Python select.KQ_EV_ENABLE屬性的具體用法?Python select.KQ_EV_ENABLE怎麽用?Python select.KQ_EV_ENABLE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類select
的用法示例。
在下文中一共展示了select.KQ_EV_ENABLE屬性的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_issue30058
# 需要導入模塊: import select [as 別名]
# 或者: from select import KQ_EV_ENABLE [as 別名]
def test_issue30058(self):
# changelist must be an iterable
kq = select.kqueue()
a, b = socket.socketpair()
ev = select.kevent(a, select.KQ_FILTER_READ, select.KQ_EV_ADD | select.KQ_EV_ENABLE)
kq.control([ev], 0)
# not a list
kq.control((ev,), 0)
# __len__ is not consistent with __iter__
class BadList:
def __len__(self):
return 0
def __iter__(self):
for i in range(100):
yield ev
kq.control(BadList(), 0)
# doesn't have __len__
kq.control(iter([ev]), 0)
a.close()
b.close()
kq.close()
示例2: modifyRegistrationForEvents
# 需要導入模塊: import select [as 別名]
# 或者: from select import KQ_EV_ENABLE [as 別名]
def modifyRegistrationForEvents(self, asyncSocket, readEvents, writeEvents):
fileno = asyncSocket.fileno()
if readEvents:
readKE = select.kevent(ident = fileno,
filter = select.KQ_FILTER_READ,
flags = select.KQ_EV_ENABLE)
else:
readKE = select.kevent(ident = fileno,
filter = select.KQ_FILTER_READ,
flags = select.KQ_EV_DISABLE)
if writeEvents:
writeKE = select.kevent(ident = fileno,
filter = select.KQ_FILTER_WRITE,
flags = select.KQ_EV_ENABLE)
else:
writeKE = select.kevent(ident = fileno,
filter = select.KQ_FILTER_WRITE,
flags = select.KQ_EV_DISABLE)
# Should be able to put readKE and writeKE in a list in
# one call to kqueue.control, but this is broken due to Python issue 5910
self.__kqueue.control([readKE], 0, 0)
self.__kqueue.control([writeKE], 0, 0)
示例3: testPair
# 需要導入模塊: import select [as 別名]
# 或者: from select import KQ_EV_ENABLE [as 別名]
def testPair(self):
kq = select.kqueue()
a, b = socket.socketpair()
a.send(b'foo')
event1 = select.kevent(a, select.KQ_FILTER_READ, select.KQ_EV_ADD | select.KQ_EV_ENABLE)
event2 = select.kevent(b, select.KQ_FILTER_READ, select.KQ_EV_ADD | select.KQ_EV_ENABLE)
r = kq.control([event1, event2], 1, 1)
self.assertTrue(r)
self.assertFalse(r[0].flags & select.KQ_EV_ERROR)
self.assertEqual(b.recv(r[0].data), b'foo')
a.close()
b.close()
kq.close()
示例4: register
# 需要導入模塊: import select [as 別名]
# 或者: from select import KQ_EV_ENABLE [as 別名]
def register(self, key, f):
BasePoller.register(self, key, f)
r_event = select.kevent(
f.fileno(), filter=select.KQ_FILTER_READ,
flags=select.KQ_EV_ADD | select.KQ_EV_ENABLE)
self.events.append(r_event)
w_event = select.kevent(
f.fileno(), filter=select.KQ_FILTER_WRITE,
flags=select.KQ_EV_ADD | select.KQ_EV_ENABLE)
self.events.append(w_event)
self.event_to_object[f.fileno()] = f
示例5: _is_closed_kqueue
# 需要導入模塊: import select [as 別名]
# 或者: from select import KQ_EV_ENABLE [as 別名]
def _is_closed_kqueue(f):
kqueue = select.kqueue()
event = select.kevent(
f.fileno(), filter=select.KQ_FILTER_READ,
flags=select.KQ_EV_ADD | select.KQ_EV_ENABLE)
for event in kqueue.control([event], 128, 0.0):
if event.flags & select.KQ_EV_EOF:
return True
return False
示例6: __add_ev_read
# 需要導入模塊: import select [as 別名]
# 或者: from select import KQ_EV_ENABLE [as 別名]
def __add_ev_read(self, fileno):
"""
Note:if the event exists,it will not do anything
"""
if fileno not in self.__rlist and self.__async_mode == "select":
self.__rlist.append(fileno)
if self.__async_mode == "epoll":
if fileno not in self.__epoll_register_info:
self.__epoll_register_info[fileno] = None
eventmask = self.__epoll_register_info[fileno]
event = select.EPOLLIN
if eventmask == None:
eventmask = event
self.__epoll_object.register(fileno, eventmask)
self.__epoll_register_info[fileno] = eventmask
return
is_register_read = (eventmask & select.EPOLLIN) == select.EPOLLIN
if is_register_read == False:
eventmask = event | eventmask
self.__epoll_object.modify(fileno, eventmask)
if self.__async_mode == "kqueue":
filter_ = select.KQ_FILTER_READ
flags = select.KQ_EV_ADD | select.KQ_EV_ENABLE
if fileno not in self.__kqueue_event_map:
kevent = select.kevent(fileno, filter_, flags)
kevent.udata = 0
else:
kevent = self.__kqueue_event_map[fileno]
read_exists = (kevent.udata & EV_TYPE_READ) == EV_TYPE_READ
if read_exists == False:
kevent.filter = filter_
kevent.udata = (kevent.udata | EV_TYPE_READ)
kevent.flags = flags
if fileno not in self.__kqueue_change_event_map:
self.__kqueue_change_event_map[fileno] = []
self.__kqueue_change_event_map[fileno].append(kevent)
''''''
return
示例7: __add_ev_write
# 需要導入模塊: import select [as 別名]
# 或者: from select import KQ_EV_ENABLE [as 別名]
def __add_ev_write(self, fileno):
if fileno not in self.__wlist and self.__async_mode == "select":
self.__wlist.append(fileno)
if self.__async_mode == "epoll":
if fileno not in self.__epoll_register_info:
self.__epoll_register_info[fileno] = None
eventmask = self.__epoll_register_info[fileno]
event = select.EPOLLOUT
if eventmask == None:
eventmask = event
self.__epoll_object.register(fileno, eventmask)
self.__epoll_register_info[fileno] = eventmask
return
is_register_write = (eventmask & select.EPOLLOUT) == select.EPOLLOUT
if is_register_write == False:
eventmask = event | eventmask
self.__epoll_object.modify(fileno, eventmask)
if self.__async_mode == "kqueue":
filter_ = select.KQ_FILTER_WRITE
flags = select.KQ_EV_ADD | select.KQ_EV_ENABLE
if fileno not in self.__kqueue_event_map:
kevent = select.kevent(fileno, filter_, flags)
kevent.udata = 0
else:
kevent = self.__kqueue_event_map[fileno]
write_exists = (kevent.udata & EV_TYPE_WRITE) == EV_TYPE_WRITE
if write_exists == False:
kevent.filter = filter_
kevent.flags = flags
kevent.udata = (kevent.udata | EV_TYPE_WRITE)
if fileno not in self.__kqueue_change_event_map:
self.__kqueue_change_event_map[fileno] = []
self.__kqueue_change_event_map[fileno].append(kevent)
''''''
return