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


Python asyncio.TimerHandle方法代码示例

本文整理汇总了Python中asyncio.TimerHandle方法的典型用法代码示例。如果您正苦于以下问题:Python asyncio.TimerHandle方法的具体用法?Python asyncio.TimerHandle怎么用?Python asyncio.TimerHandle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在asyncio的用法示例。


在下文中一共展示了asyncio.TimerHandle方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run_in_executor

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import TimerHandle [as 别名]
def run_in_executor(self, executor, callback, *args):
        """Run callback in executor.

        If no executor is provided, the default executor will be used, which defers execution to
        a background thread.
        """
        self._logger.debug('Running callback {} with args {} in executor'.format(callback, args))
        if isinstance(callback, asyncio.Handle):
            assert not args
            assert not isinstance(callback, asyncio.TimerHandle)
            if callback._cancelled:
                f = asyncio.Future()
                f.set_result(None)
                return f
            callback, args = callback.callback, callback.args

        if executor is None:
            self._logger.debug('Using default executor')
            executor = self.__default_executor

        if executor is None:
            self._logger.debug('Creating default executor')
            executor = self.__default_executor = QThreadExecutor()

        return asyncio.wrap_future(executor.submit(callback, *args)) 
开发者ID:gmarull,项目名称:asyncqt,代码行数:27,代码来源:__init__.py

示例2: test_timer

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import TimerHandle [as 别名]
def test_timer(self):
        def callback(*args):
            return args

        args = (1, 2, 3)
        when = time.monotonic()
        h = asyncio.TimerHandle(when, callback, args, mock.Mock())
        self.assertIs(h._callback, callback)
        self.assertIs(h._args, args)
        self.assertFalse(h._cancelled)

        # cancel
        h.cancel()
        self.assertTrue(h._cancelled)
        self.assertIsNone(h._callback)
        self.assertIsNone(h._args)

        # when cannot be None
        self.assertRaises(AssertionError,
                          asyncio.TimerHandle, None, callback, args,
                          self.loop) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:23,代码来源:test_events.py

示例3: test_timer_repr_debug

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import TimerHandle [as 别名]
def test_timer_repr_debug(self):
        self.loop.get_debug.return_value = True

        # simple function
        create_filename = __file__
        create_lineno = sys._getframe().f_lineno + 1
        h = asyncio.TimerHandle(123, noop, (), self.loop)
        filename, lineno = test_utils.get_function_source(noop)
        self.assertEqual(repr(h),
                        '<TimerHandle when=123 noop() '
                        'at %s:%s created at %s:%s>'
                        % (filename, lineno, create_filename, create_lineno))

        # cancelled handle
        h.cancel()
        self.assertEqual(repr(h),
                        '<TimerHandle cancelled when=123 noop() '
                        'at %s:%s created at %s:%s>'
                        % (filename, lineno, create_filename, create_lineno)) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:21,代码来源:test_events.py

示例4: test__run_once

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import TimerHandle [as 别名]
def test__run_once(self):
        h1 = asyncio.TimerHandle(time.monotonic() + 5.0, lambda: True, (),
                                 self.loop)
        h2 = asyncio.TimerHandle(time.monotonic() + 10.0, lambda: True, (),
                                 self.loop)

        h1.cancel()

        self.loop._process_events = mock.Mock()
        self.loop._scheduled.append(h1)
        self.loop._scheduled.append(h2)
        self.loop._run_once()

        t = self.loop._selector.select.call_args[0][0]
        self.assertTrue(9.5 < t < 10.5, t)
        self.assertEqual([h2], self.loop._scheduled)
        self.assertTrue(self.loop._process_events.called) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:19,代码来源:test_base_events.py

示例5: test__run_once_schedule_handle

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import TimerHandle [as 别名]
def test__run_once_schedule_handle(self):
        handle = None
        processed = False

        def cb(loop):
            nonlocal processed, handle
            processed = True
            handle = loop.call_soon(lambda: True)

        h = asyncio.TimerHandle(time.monotonic() - 1, cb, (self.loop,),
                                self.loop)

        self.loop._process_events = mock.Mock()
        self.loop._scheduled.append(h)
        self.loop._run_once()

        self.assertTrue(processed)
        self.assertEqual([handle], list(self.loop._ready)) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:20,代码来源:test_base_events.py

示例6: __init__

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import TimerHandle [as 别名]
def __init__(
        self,
        request: Message,
        addr: Tuple[str, int],
        protocol,
        retransmissions: Optional[int] = None,
    ) -> None:
        self.__addr = addr
        self.__future: asyncio.Future[
            Tuple[Message, Tuple[str, int]]
        ] = asyncio.Future()
        self.__request = request
        self.__timeout_delay = RETRY_RTO
        self.__timeout_handle: Optional[asyncio.TimerHandle] = None
        self.__protocol = protocol
        self.__tries = 0
        self.__tries_max = 1 + (
            retransmissions if retransmissions is not None else RETRY_MAX
        ) 
开发者ID:aiortc,项目名称:aioice,代码行数:21,代码来源:stun.py

示例7: __init__

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import TimerHandle [as 别名]
def __init__(self,
                 loop: asyncio.AbstractEventLoop) -> None:
        BaseProtocol.__init__(self, loop=loop)
        DataQueue.__init__(self, loop)

        self._should_close = False

        self._payload = None
        self._skip_payload = False
        self._payload_parser = None

        self._timer = None

        self._tail = b''
        self._upgraded = False
        self._parser = None  # type: Optional[HttpResponseParser]

        self._read_timeout = None  # type: Optional[float]
        self._read_timeout_handle = None  # type: Optional[asyncio.TimerHandle] 
开发者ID:TouwaStar,项目名称:Galaxy_Plugin_Bethesda,代码行数:21,代码来源:client_proto.py

示例8: __init__

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import TimerHandle [as 别名]
def __init__(self, servers, timeout, retry_policy, allow_read_only, read_timeout, loop):
        self.loop = loop
        self.hosts = []
        for server in servers.split(","):
            ipv6_match = re.match(r'\[(.*)\]:(\d+)$', server)
            if ipv6_match is not None:
                host, port = ipv6_match.groups()
            elif ":" in server:
                host, port = server.rsplit(":", 1)
            else:
                host = server
                port = DEFAULT_ZOOKEEPER_PORT

            self.hosts.append((host, port))

        self.conn = None
        self.state = SessionStateMachine(session=self)

        self.retry_policy = retry_policy or RetryPolicy.forever()
        self.allow_read_only = allow_read_only

        self.xid = 0
        self.last_zxid = None

        self.session_id = None
        self.timeout = timeout
        self.password = b'\x00'
        self.read_timeout = read_timeout

        self.repair_loop_task = None

        # asyncio.TimerHandle object
        self.heartbeat_handle = None
        # asyncio.Task object
        self.heartbeat_task = None

        self.watch_callbacks = collections.defaultdict(set)

        self.started = False
        self.closing = False 
开发者ID:micro-fan,项目名称:aiozk,代码行数:42,代码来源:session.py

示例9: test_hash

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import TimerHandle [as 别名]
def test_hash(self):
        when = time.monotonic()
        h = asyncio.TimerHandle(when, lambda: False, (),
                                mock.Mock())
        self.assertEqual(hash(h), hash(when)) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:7,代码来源:test_events.py

示例10: test_timer_repr

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import TimerHandle [as 别名]
def test_timer_repr(self):
        self.loop.get_debug.return_value = False

        # simple function
        h = asyncio.TimerHandle(123, noop, (), self.loop)
        src = test_utils.get_function_source(noop)
        self.assertEqual(repr(h),
                        '<TimerHandle when=123 noop() at %s:%s>' % src)

        # cancelled handle
        h.cancel()
        self.assertEqual(repr(h),
                        '<TimerHandle cancelled when=123>') 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:15,代码来源:test_events.py

示例11: test_timer_comparison

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import TimerHandle [as 别名]
def test_timer_comparison(self):
        def callback(*args):
            return args

        when = time.monotonic()

        h1 = asyncio.TimerHandle(when, callback, (), self.loop)
        h2 = asyncio.TimerHandle(when, callback, (), self.loop)
        # TODO: Use assertLess etc.
        self.assertFalse(h1 < h2)
        self.assertFalse(h2 < h1)
        self.assertTrue(h1 <= h2)
        self.assertTrue(h2 <= h1)
        self.assertFalse(h1 > h2)
        self.assertFalse(h2 > h1)
        self.assertTrue(h1 >= h2)
        self.assertTrue(h2 >= h1)
        self.assertTrue(h1 == h2)
        self.assertFalse(h1 != h2)

        h2.cancel()
        self.assertFalse(h1 == h2)

        h1 = asyncio.TimerHandle(when, callback, (), self.loop)
        h2 = asyncio.TimerHandle(when + 10.0, callback, (), self.loop)
        self.assertTrue(h1 < h2)
        self.assertFalse(h2 < h1)
        self.assertTrue(h1 <= h2)
        self.assertFalse(h2 <= h1)
        self.assertFalse(h1 > h2)
        self.assertTrue(h2 > h1)
        self.assertFalse(h1 >= h2)
        self.assertTrue(h2 >= h1)
        self.assertFalse(h1 == h2)
        self.assertTrue(h1 != h2)

        h3 = asyncio.Handle(callback, (), self.loop)
        self.assertIs(NotImplemented, h1.__eq__(h3))
        self.assertIs(NotImplemented, h1.__ne__(h3)) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:41,代码来源:test_events.py

示例12: test_run_once_in_executor_handle

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import TimerHandle [as 别名]
def test_run_once_in_executor_handle(self):
        def cb():
            pass

        self.assertRaises(
            AssertionError, self.loop.run_in_executor,
            None, asyncio.Handle(cb, (), self.loop), ('',))
        self.assertRaises(
            AssertionError, self.loop.run_in_executor,
            None, asyncio.TimerHandle(10, cb, (), self.loop)) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:12,代码来源:test_base_events.py

示例13: test_default_exc_handler_callback

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import TimerHandle [as 别名]
def test_default_exc_handler_callback(self):
        self.loop._process_events = mock.Mock()

        def zero_error(fut):
            fut.set_result(True)
            1/0

        # Test call_soon (events.Handle)
        with mock.patch('asyncio.base_events.logger') as log:
            fut = asyncio.Future(loop=self.loop)
            self.loop.call_soon(zero_error, fut)
            fut.add_done_callback(lambda fut: self.loop.stop())
            self.loop.run_forever()
            log.error.assert_called_with(
                test_utils.MockPattern('Exception in callback.*zero'),
                exc_info=(ZeroDivisionError, MOCK_ANY, MOCK_ANY))

        # Test call_later (events.TimerHandle)
        with mock.patch('asyncio.base_events.logger') as log:
            fut = asyncio.Future(loop=self.loop)
            self.loop.call_later(0.01, zero_error, fut)
            fut.add_done_callback(lambda fut: self.loop.stop())
            self.loop.run_forever()
            log.error.assert_called_with(
                test_utils.MockPattern('Exception in callback.*zero'),
                exc_info=(ZeroDivisionError, MOCK_ANY, MOCK_ANY)) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:28,代码来源:test_base_events.py


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