本文整理汇总了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)