本文整理匯總了Python中select.devpoll方法的典型用法代碼示例。如果您正苦於以下問題:Python select.devpoll方法的具體用法?Python select.devpoll怎麽用?Python select.devpoll使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類select
的用法示例。
在下文中一共展示了select.devpoll方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: select
# 需要導入模塊: import select [as 別名]
# 或者: from select import devpoll [as 別名]
def select(self, timeout=None):
if timeout is None:
timeout = None
elif timeout <= 0:
timeout = 0
else:
# devpoll() has a resolution of 1 millisecond, round away from
# zero to wait *at least* timeout seconds.
timeout = math.ceil(timeout * 1e3)
ready = []
try:
fd_event_list = self._devpoll.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
示例2: test_close
# 需要導入模塊: import select [as 別名]
# 或者: from select import devpoll [as 別名]
def test_close(self):
open_file = open(__file__, "rb")
self.addCleanup(open_file.close)
fd = open_file.fileno()
devpoll = select.devpoll()
# test fileno() method and closed attribute
self.assertIsInstance(devpoll.fileno(), int)
self.assertFalse(devpoll.closed)
# test close()
devpoll.close()
self.assertTrue(devpoll.closed)
self.assertRaises(ValueError, devpoll.fileno)
# close() can be called more than once
devpoll.close()
# operations must fail with ValueError("I/O operation on closed ...")
self.assertRaises(ValueError, devpoll.modify, fd, select.POLLIN)
self.assertRaises(ValueError, devpoll.poll)
self.assertRaises(ValueError, devpoll.register, fd, fd, select.POLLIN)
self.assertRaises(ValueError, devpoll.unregister, fd)
示例3: test_timeout_overflow
# 需要導入模塊: import select [as 別名]
# 或者: from select import devpoll [as 別名]
def test_timeout_overflow(self):
pollster = select.devpoll()
w, r = os.pipe()
pollster.register(w)
pollster.poll(-1)
self.assertRaises(OverflowError, pollster.poll, -2)
self.assertRaises(OverflowError, pollster.poll, -1 << 31)
self.assertRaises(OverflowError, pollster.poll, -1 << 64)
pollster.poll(0)
pollster.poll(1)
pollster.poll(1 << 30)
self.assertRaises(OverflowError, pollster.poll, 1 << 31)
self.assertRaises(OverflowError, pollster.poll, 1 << 63)
self.assertRaises(OverflowError, pollster.poll, 1 << 64)
示例4: __init__
# 需要導入模塊: import select [as 別名]
# 或者: from select import devpoll [as 別名]
def __init__(self):
super(DevpollSelector, self).__init__()
self._devpoll = select.devpoll()
示例5: close
# 需要導入模塊: import select [as 別名]
# 或者: from select import devpoll [as 別名]
def close(self):
self._kqueue.close()
super(KqueueSelector, self).close()
# Choose the best implementation: roughly, epoll|kqueue|devpoll > poll > select.
# select() also can't accept a FD > FD_SETSIZE (usually around 1024)
示例6: fileno
# 需要導入模塊: import select [as 別名]
# 或者: from select import devpoll [as 別名]
def fileno(self):
"""Return devpoll() fd."""
return self._poller.fileno()
示例7: __init__
# 需要導入模塊: import select [as 別名]
# 或者: from select import devpoll [as 別名]
def __init__(self):
super().__init__()
self._devpoll = select.devpoll()
示例8: close
# 需要導入模塊: import select [as 別名]
# 或者: from select import devpoll [as 別名]
def close(self):
self._kqueue.close()
super().close()
# Choose the best implementation, roughly:
# epoll|kqueue|devpoll > poll > select.
# select() also can't accept a FD > FD_SETSIZE (usually around 1024)
示例9: test_devpoll
# 需要導入模塊: import select [as 別名]
# 或者: from select import devpoll [as 別名]
def test_devpoll(self):
poller = select.devpoll()
self.addCleanup(poller.close)
t0 = time.monotonic()
poller.poll(self.sleep_time * 1e3)
dt = time.monotonic() - t0
self.stop_alarm()
self.assertGreaterEqual(dt, self.sleep_time)
示例10: test_fd_non_inheritable
# 需要導入模塊: import select [as 別名]
# 或者: from select import devpoll [as 別名]
def test_fd_non_inheritable(self):
devpoll = select.devpoll()
self.addCleanup(devpoll.close)
self.assertEqual(os.get_inheritable(devpoll.fileno()), False)
示例11: test_events_mask_overflow
# 需要導入模塊: import select [as 別名]
# 或者: from select import devpoll [as 別名]
def test_events_mask_overflow(self):
pollster = select.devpoll()
w, r = os.pipe()
pollster.register(w)
# Issue #17919
self.assertRaises(OverflowError, pollster.register, 0, -1)
self.assertRaises(OverflowError, pollster.register, 0, 1 << 64)
self.assertRaises(OverflowError, pollster.modify, 1, -1)
self.assertRaises(OverflowError, pollster.modify, 1, 1 << 64)
示例12: test_events_mask_overflow_c_limits
# 需要導入模塊: import select [as 別名]
# 或者: from select import devpoll [as 別名]
def test_events_mask_overflow_c_limits(self):
from _testcapi import USHRT_MAX
pollster = select.devpoll()
w, r = os.pipe()
pollster.register(w)
# Issue #17919
self.assertRaises(OverflowError, pollster.register, 0, USHRT_MAX + 1)
self.assertRaises(OverflowError, pollster.modify, 1, USHRT_MAX + 1)
示例13: close
# 需要導入模塊: import select [as 別名]
# 或者: from select import devpoll [as 別名]
def close(self):
self._selector.close()
super().close()
# Choose the best implementation, roughly:
# epoll|kqueue|devpoll > poll > select.
# select() also can't accept a FD > FD_SETSIZE (usually around 1024)