当前位置: 首页>>代码示例>>Python>>正文


Python selectors.EVENT_READ属性代码示例

本文整理汇总了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) 
开发者ID:hhstore,项目名称:annotated-py-asyncio,代码行数:18,代码来源:test_selector_events.py

示例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) 
开发者ID:hhstore,项目名称:annotated-py-asyncio,代码行数:27,代码来源:test_selectors.py

示例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) 
开发者ID:hhstore,项目名称:annotated-py-asyncio,代码行数:18,代码来源:test_selectors.py

示例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) 
开发者ID:hhstore,项目名称:annotated-py-asyncio,代码行数:19,代码来源:test_selectors.py

示例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) 
开发者ID:hhstore,项目名称:annotated-py-asyncio,代码行数:27,代码来源:test_selectors.py

示例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) 
开发者ID:hhstore,项目名称:annotated-py-asyncio,代码行数:18,代码来源:test_selectors.py

示例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) 
开发者ID:hhstore,项目名称:annotated-py-asyncio,代码行数:13,代码来源:test_selector_events.py

示例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) 
开发者ID:hhstore,项目名称:annotated-py-asyncio,代码行数:16,代码来源:test_selector_events.py

示例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) 
开发者ID:hhstore,项目名称:annotated-py-asyncio,代码行数:8,代码来源:test_selector_events.py

示例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]) 
开发者ID:hhstore,项目名称:annotated-py-asyncio,代码行数:15,代码来源:test_selector_events.py

示例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]) 
开发者ID:hhstore,项目名称:annotated-py-asyncio,代码行数:15,代码来源:test_selector_events.py

示例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) 
开发者ID:hhstore,项目名称:annotated-py-asyncio,代码行数:13,代码来源:test_selector_events.py

示例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) 
开发者ID:hhstore,项目名称:annotated-py-asyncio,代码行数:12,代码来源:test_selector_events.py

示例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) 
开发者ID:hhstore,项目名称:annotated-py-asyncio,代码行数:16,代码来源:test_selectors.py

示例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) 
开发者ID:hhstore,项目名称:annotated-py-asyncio,代码行数:12,代码来源:test_selectors.py


注:本文中的asyncio.selectors.EVENT_READ属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。