本文整理汇总了Python中asyncio.selectors.EVENT_READ属性的典型用法代码示例。如果您正苦于以下问题:Python selectors.EVENT_READ属性的具体用法?Python selectors.EVENT_READ怎么用?Python selectors.EVENT_READ使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类asyncio.selectors
的用法示例。
在下文中一共展示了selectors.EVENT_READ属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_add_reader_existing
# 需要导入模块: from asyncio import selectors [as 别名]
# 或者: from asyncio.selectors import EVENT_READ [as 别名]
def test_add_reader_existing(self):
reader = mock.Mock()
writer = mock.Mock()
self.loop._selector.get_key.return_value = selectors.SelectorKey(
1, 1, selectors.EVENT_WRITE, (reader, writer))
cb = lambda: True
self.loop.add_reader(1, cb)
self.assertTrue(reader.cancel.called)
self.assertFalse(self.loop._selector.register.called)
self.assertTrue(self.loop._selector.modify.called)
fd, mask, (r, w) = self.loop._selector.modify.call_args[0]
self.assertEqual(1, fd)
self.assertEqual(selectors.EVENT_WRITE | selectors.EVENT_READ, mask)
self.assertEqual(cb, r._callback)
self.assertEqual(writer, w)
示例2: test_register
# 需要导入模块: from asyncio import selectors [as 别名]
# 或者: from asyncio.selectors import EVENT_READ [as 别名]
def test_register(self):
s = self.SELECTOR()
self.addCleanup(s.close)
rd, wr = self.make_socketpair()
key = s.register(rd, selectors.EVENT_READ, "data")
self.assertIsInstance(key, selectors.SelectorKey)
self.assertEqual(key.fileobj, rd)
self.assertEqual(key.fd, rd.fileno())
self.assertEqual(key.events, selectors.EVENT_READ)
self.assertEqual(key.data, "data")
# register an unknown event
self.assertRaises(ValueError, s.register, 0, 999999)
# register an invalid FD
self.assertRaises(ValueError, s.register, -10, selectors.EVENT_READ)
# register twice
self.assertRaises(KeyError, s.register, rd, selectors.EVENT_READ)
# register the same FD, but with a different object
self.assertRaises(KeyError, s.register, rd.fileno(),
selectors.EVENT_READ)
示例3: test_unregister_after_fd_close_and_reuse
# 需要导入模块: from asyncio import selectors [as 别名]
# 或者: from asyncio.selectors import EVENT_READ [as 别名]
def test_unregister_after_fd_close_and_reuse(self):
s = self.SELECTOR()
self.addCleanup(s.close)
rd, wr = self.make_socketpair()
r, w = rd.fileno(), wr.fileno()
s.register(r, selectors.EVENT_READ)
s.register(w, selectors.EVENT_WRITE)
rd2, wr2 = self.make_socketpair()
rd.close()
wr.close()
os.dup2(rd2.fileno(), r)
os.dup2(wr2.fileno(), w)
self.addCleanup(os.close, r)
self.addCleanup(os.close, w)
s.unregister(r)
s.unregister(w)
示例4: test_select
# 需要导入模块: from asyncio import selectors [as 别名]
# 或者: from asyncio.selectors import EVENT_READ [as 别名]
def test_select(self):
s = self.SELECTOR()
self.addCleanup(s.close)
rd, wr = self.make_socketpair()
s.register(rd, selectors.EVENT_READ)
wr_key = s.register(wr, selectors.EVENT_WRITE)
result = s.select()
for key, events in result:
self.assertTrue(isinstance(key, selectors.SelectorKey))
self.assertTrue(events)
self.assertFalse(events & ~(selectors.EVENT_READ |
selectors.EVENT_WRITE))
self.assertEqual([(wr_key, selectors.EVENT_WRITE)], result)
示例5: test_timeout
# 需要导入模块: from asyncio import selectors [as 别名]
# 或者: from asyncio.selectors import EVENT_READ [as 别名]
def test_timeout(self):
s = self.SELECTOR()
self.addCleanup(s.close)
rd, wr = self.make_socketpair()
s.register(wr, selectors.EVENT_WRITE)
t = time()
self.assertEqual(1, len(s.select(0)))
self.assertEqual(1, len(s.select(-1)))
self.assertLess(time() - t, 0.5)
s.unregister(wr)
s.register(rd, selectors.EVENT_READ)
t = time()
self.assertFalse(s.select(0))
self.assertFalse(s.select(-1))
self.assertLess(time() - t, 0.5)
t0 = time()
self.assertFalse(s.select(1))
t1 = time()
dt = t1 - t0
# Tolerate 2.0 seconds for very slow buildbots
self.assertTrue(0.8 <= dt <= 2.0, dt)
示例6: test_select_interrupt
# 需要导入模块: from asyncio import selectors [as 别名]
# 或者: from asyncio.selectors import EVENT_READ [as 别名]
def test_select_interrupt(self):
s = self.SELECTOR()
self.addCleanup(s.close)
rd, wr = self.make_socketpair()
orig_alrm_handler = signal.signal(signal.SIGALRM, lambda *args: None)
self.addCleanup(signal.signal, signal.SIGALRM, orig_alrm_handler)
self.addCleanup(signal.alarm, 0)
signal.alarm(1)
s.register(rd, selectors.EVENT_READ)
t = time()
self.assertFalse(s.select(2))
self.assertLess(time() - t, 2.5)
示例7: test_add_reader
# 需要导入模块: from asyncio import selectors [as 别名]
# 或者: from asyncio.selectors import EVENT_READ [as 别名]
def test_add_reader(self):
self.loop._selector.get_key.side_effect = KeyError
cb = lambda: True
self.loop.add_reader(1, cb)
self.assertTrue(self.loop._selector.register.called)
fd, mask, (r, w) = self.loop._selector.register.call_args[0]
self.assertEqual(1, fd)
self.assertEqual(selectors.EVENT_READ, mask)
self.assertEqual(cb, r._callback)
self.assertIsNone(w)
示例8: test_add_reader_existing_writer
# 需要导入模块: from asyncio import selectors [as 别名]
# 或者: from asyncio.selectors import EVENT_READ [as 别名]
def test_add_reader_existing_writer(self):
writer = mock.Mock()
self.loop._selector.get_key.return_value = selectors.SelectorKey(
1, 1, selectors.EVENT_WRITE, (None, writer))
cb = lambda: True
self.loop.add_reader(1, cb)
self.assertFalse(self.loop._selector.register.called)
self.assertTrue(self.loop._selector.modify.called)
fd, mask, (r, w) = self.loop._selector.modify.call_args[0]
self.assertEqual(1, fd)
self.assertEqual(selectors.EVENT_WRITE | selectors.EVENT_READ, mask)
self.assertEqual(cb, r._callback)
self.assertEqual(writer, w)
示例9: test_remove_reader
# 需要导入模块: from asyncio import selectors [as 别名]
# 或者: from asyncio.selectors import EVENT_READ [as 别名]
def test_remove_reader(self):
self.loop._selector.get_key.return_value = selectors.SelectorKey(
1, 1, selectors.EVENT_READ, (None, None))
self.assertFalse(self.loop.remove_reader(1))
self.assertTrue(self.loop._selector.unregister.called)
示例10: test_remove_reader_read_write
# 需要导入模块: from asyncio import selectors [as 别名]
# 或者: from asyncio.selectors import EVENT_READ [as 别名]
def test_remove_reader_read_write(self):
reader = mock.Mock()
writer = mock.Mock()
self.loop._selector.get_key.return_value = selectors.SelectorKey(
1, 1, selectors.EVENT_READ | selectors.EVENT_WRITE,
(reader, writer))
self.assertTrue(
self.loop.remove_reader(1))
self.assertFalse(self.loop._selector.unregister.called)
self.assertEqual(
(1, selectors.EVENT_WRITE, (None, writer)),
self.loop._selector.modify.call_args[0])
示例11: test_remove_writer_read_write
# 需要导入模块: from asyncio import selectors [as 别名]
# 或者: from asyncio.selectors import EVENT_READ [as 别名]
def test_remove_writer_read_write(self):
reader = mock.Mock()
writer = mock.Mock()
self.loop._selector.get_key.return_value = selectors.SelectorKey(
1, 1, selectors.EVENT_READ | selectors.EVENT_WRITE,
(reader, writer))
self.assertTrue(
self.loop.remove_writer(1))
self.assertFalse(self.loop._selector.unregister.called)
self.assertEqual(
(1, selectors.EVENT_READ, (reader, None)),
self.loop._selector.modify.call_args[0])
示例12: test_process_events_read
# 需要导入模块: from asyncio import selectors [as 别名]
# 或者: from asyncio.selectors import EVENT_READ [as 别名]
def test_process_events_read(self):
reader = mock.Mock()
reader._cancelled = False
self.loop._add_callback = mock.Mock()
self.loop._process_events(
[(selectors.SelectorKey(
1, 1, selectors.EVENT_READ, (reader, None)),
selectors.EVENT_READ)])
self.assertTrue(self.loop._add_callback.called)
self.loop._add_callback.assert_called_with(reader)
示例13: test_process_events_read_cancelled
# 需要导入模块: from asyncio import selectors [as 别名]
# 或者: from asyncio.selectors import EVENT_READ [as 别名]
def test_process_events_read_cancelled(self):
reader = mock.Mock()
reader.cancelled = True
self.loop.remove_reader = mock.Mock()
self.loop._process_events(
[(selectors.SelectorKey(
1, 1, selectors.EVENT_READ, (reader, None)),
selectors.EVENT_READ)])
self.loop.remove_reader.assert_called_with(1)
示例14: test_unregister
# 需要导入模块: from asyncio import selectors [as 别名]
# 或者: from asyncio.selectors import EVENT_READ [as 别名]
def test_unregister(self):
s = self.SELECTOR()
self.addCleanup(s.close)
rd, wr = self.make_socketpair()
s.register(rd, selectors.EVENT_READ)
s.unregister(rd)
# unregister an unknown file obj
self.assertRaises(KeyError, s.unregister, 999999)
# unregister twice
self.assertRaises(KeyError, s.unregister, rd)
示例15: test_unregister_after_socket_close
# 需要导入模块: from asyncio import selectors [as 别名]
# 或者: from asyncio.selectors import EVENT_READ [as 别名]
def test_unregister_after_socket_close(self):
s = self.SELECTOR()
self.addCleanup(s.close)
rd, wr = self.make_socketpair()
s.register(rd, selectors.EVENT_READ)
s.register(wr, selectors.EVENT_WRITE)
rd.close()
wr.close()
s.unregister(rd)
s.unregister(wr)