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


Python ioloop.PeriodicCallback方法代码示例

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


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

示例1: start

# 需要导入模块: from tornado import ioloop [as 别名]
# 或者: from tornado.ioloop import PeriodicCallback [as 别名]
def start(check_time: int = 500) -> None:
    """Begins watching source files for changes.

    .. versionchanged:: 5.0
       The ``io_loop`` argument (deprecated since version 4.1) has been removed.
    """
    io_loop = ioloop.IOLoop.current()
    if io_loop in _io_loops:
        return
    _io_loops[io_loop] = True
    if len(_io_loops) > 1:
        gen_log.warning("tornado.autoreload started more than once in the same process")
    modify_times = {}  # type: Dict[str, float]
    callback = functools.partial(_reload_on_update, modify_times)
    scheduler = ioloop.PeriodicCallback(callback, check_time)
    scheduler.start() 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:18,代码来源:autoreload.py

示例2: start

# 需要导入模块: from tornado import ioloop [as 别名]
# 或者: from tornado.ioloop import PeriodicCallback [as 别名]
def start(io_loop=None, check_time=500):
    """Begins watching source files for changes.

    .. versionchanged:: 4.1
       The ``io_loop`` argument is deprecated.
    """
    io_loop = io_loop or ioloop.IOLoop.current()
    if io_loop in _io_loops:
        return
    _io_loops[io_loop] = True
    if len(_io_loops) > 1:
        gen_log.warning("tornado.autoreload started more than once in the same process")
    if _has_execv:
        add_reload_hook(functools.partial(io_loop.close, all_fds=True))
    modify_times = {}
    callback = functools.partial(_reload_on_update, modify_times)
    scheduler = ioloop.PeriodicCallback(callback, check_time, io_loop=io_loop)
    scheduler.start() 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:20,代码来源:autoreload.py

示例3: test_overrun

# 需要导入模块: from tornado import ioloop [as 别名]
# 或者: from tornado.ioloop import PeriodicCallback [as 别名]
def test_overrun(self):
        sleep_durations = [9, 9, 10, 11, 20, 20, 35, 35, 0, 0]
        expected = [
            1010, 1020, 1030,  # first 3 calls on schedule
            1050, 1070,  # next 2 delayed one cycle
            1100, 1130,  # next 2 delayed 2 cycles
            1170, 1210,  # next 2 delayed 3 cycles
            1220, 1230,  # then back on schedule.
        ]
        calls = []

        def cb():
            calls.append(self.io_loop.time())
            if not sleep_durations:
                self.io_loop.stop()
                return
            self.io_loop.sleep(sleep_durations.pop(0))
        pc = PeriodicCallback(cb, 10000)
        pc.start()
        self.io_loop.start()
        self.assertEqual(calls, expected) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:23,代码来源:ioloop_test.py

示例4: simulate_calls

# 需要导入模块: from tornado import ioloop [as 别名]
# 或者: from tornado.ioloop import PeriodicCallback [as 别名]
def simulate_calls(self, pc, durations):
        """Simulate a series of calls to the PeriodicCallback.

        Pass a list of call durations in seconds (negative values
        work to simulate clock adjustments during the call, or more or
        less equivalently, between calls). This method returns the
        times at which each call would be made.
        """
        calls = []
        now = 1000
        pc._next_timeout = now
        for d in durations:
            pc._update_next(now)
            calls.append(pc._next_timeout)
            now = pc._next_timeout + d
        return calls 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:18,代码来源:ioloop_test.py

示例5: test_overrun

# 需要导入模块: from tornado import ioloop [as 别名]
# 或者: from tornado.ioloop import PeriodicCallback [as 别名]
def test_overrun(self):
        # If a call runs for too long, we skip entire cycles to get
        # back on schedule.
        call_durations = [9, 9, 10, 11, 20, 20, 35, 35, 0, 0, 0]
        expected = [
            1010,
            1020,
            1030,  # first 3 calls on schedule
            1050,
            1070,  # next 2 delayed one cycle
            1100,
            1130,  # next 2 delayed 2 cycles
            1170,
            1210,  # next 2 delayed 3 cycles
            1220,
            1230,  # then back on schedule.
        ]

        pc = PeriodicCallback(self.dummy, 10000)
        self.assertEqual(self.simulate_calls(pc, call_durations), expected) 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:22,代码来源:ioloop_test.py

示例6: test_clock_backwards

# 需要导入模块: from tornado import ioloop [as 别名]
# 或者: from tornado.ioloop import PeriodicCallback [as 别名]
def test_clock_backwards(self):
        pc = PeriodicCallback(self.dummy, 10000)
        # Backwards jumps are ignored, potentially resulting in a
        # slightly slow schedule (although we assume that when
        # time.time() and time.monotonic() are different, time.time()
        # is getting adjusted by NTP and is therefore more accurate)
        self.assertEqual(
            self.simulate_calls(pc, [-2, -1, -3, -2, 0]), [1010, 1020, 1030, 1040, 1050]
        )

        # For big jumps, we should perhaps alter the schedule, but we
        # don't currently. This trace shows that we run callbacks
        # every 10s of time.time(), but the first and second calls are
        # 110s of real time apart because the backwards jump is
        # ignored.
        self.assertEqual(self.simulate_calls(pc, [-100, 0, 0]), [1010, 1020, 1030]) 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:18,代码来源:ioloop_test.py

示例7: start

# 需要导入模块: from tornado import ioloop [as 别名]
# 或者: from tornado.ioloop import PeriodicCallback [as 别名]
def start(check_time=500):
    """Begins watching source files for changes.

    .. versionchanged:: 5.0
       The ``io_loop`` argument (deprecated since version 4.1) has been removed.
    """
    io_loop = ioloop.IOLoop.current()
    if io_loop in _io_loops:
        return
    _io_loops[io_loop] = True
    if len(_io_loops) > 1:
        gen_log.warning("tornado.autoreload started more than once in the same process")
    modify_times = {}
    callback = functools.partial(_reload_on_update, modify_times)
    scheduler = ioloop.PeriodicCallback(callback, check_time)
    scheduler.start() 
开发者ID:tp4a,项目名称:teleport,代码行数:18,代码来源:autoreload.py

示例8: test_clock_backwards

# 需要导入模块: from tornado import ioloop [as 别名]
# 或者: from tornado.ioloop import PeriodicCallback [as 别名]
def test_clock_backwards(self):
        pc = PeriodicCallback(None, 10000)
        # Backwards jumps are ignored, potentially resulting in a
        # slightly slow schedule (although we assume that when
        # time.time() and time.monotonic() are different, time.time()
        # is getting adjusted by NTP and is therefore more accurate)
        self.assertEqual(self.simulate_calls(pc, [-2, -1, -3, -2, 0]),
                         [1010, 1020, 1030, 1040, 1050])

        # For big jumps, we should perhaps alter the schedule, but we
        # don't currently. This trace shows that we run callbacks
        # every 10s of time.time(), but the first and second calls are
        # 110s of real time apart because the backwards jump is
        # ignored.
        self.assertEqual(self.simulate_calls(pc, [-100, 0, 0]),
                         [1010, 1020, 1030]) 
开发者ID:tp4a,项目名称:teleport,代码行数:18,代码来源:ioloop_test.py

示例9: start

# 需要导入模块: from tornado import ioloop [as 别名]
# 或者: from tornado.ioloop import PeriodicCallback [as 别名]
def start(io_loop=None, check_time=500):
    """Begins watching source files for changes.

    .. versionchanged:: 4.1
       The ``io_loop`` argument is deprecated.
    """
    io_loop = io_loop or ioloop.IOLoop.current()
    if io_loop in _io_loops:
        return
    _io_loops[io_loop] = True
    if len(_io_loops) > 1:
        gen_log.warning("tornado.autoreload started more than once in the same process")
    modify_times = {}
    callback = functools.partial(_reload_on_update, modify_times)
    scheduler = ioloop.PeriodicCallback(callback, check_time, io_loop=io_loop)
    scheduler.start() 
开发者ID:zulip,项目名称:zulip,代码行数:18,代码来源:autoreload.py

示例10: __init__

# 需要导入模块: from tornado import ioloop [as 别名]
# 或者: from tornado.ioloop import PeriodicCallback [as 别名]
def __init__(self, service, host, port, timeout=30, name=None,
                 raise_empty=False, max_conn=30, connection_class=ThriftClient,
                 keepalive=None, tracking=False, tracker_factory=None,
                 use_limit=None, check_interval=10):
        super(TornadoHeartbeatClientPool, self).__init__(
            service=service,
            host=host,
            port=port,
            timeout=timeout,
            name=name,
            raise_empty=raise_empty,
            max_conn=max_conn,
            connection_class=connection_class,
            keepalive=keepalive,
            tracking=tracking,
            tracker_factory=tracker_factory,
            use_limit=use_limit,
        )
        self.check_interval = check_interval

        self._heartbeat_timer = PeriodicCallback(
            self.maintain_connections, max(1, self.timeout - 5) * 1000)
        self._heartbeat_timer.start() 
开发者ID:Thriftpy,项目名称:thrift_connector,代码行数:25,代码来源:tornado.py

示例11: __init__

# 需要导入模块: from tornado import ioloop [as 别名]
# 或者: from tornado.ioloop import PeriodicCallback [as 别名]
def __init__(self, callback, callback_time, io_loop=None):
        self.callback = callback
        self.callback_time = callback_time
        self.io_loop = io_loop or IOLoop.current()
        if self.io_loop._running:
            # Use a regular PeriodicCallback
            self._pc = PC(callback, callback_time, io_loop)
        else:
            from threading import Timer
            # NOTE: PeriodicCallback uses ms while Timer uses seconds
            def callback_wrapper():
                "Runs the callback and restarts the Timer so it will run again"
                self.callback()
                self._pc = Timer(callback_time / 1000, callback_wrapper)
                if self._running:
                    self._pc.start()
            self._pc = Timer(callback_time / 1000, callback_wrapper)
        self._running = False 
开发者ID:jimmy201602,项目名称:django-gateone,代码行数:20,代码来源:async.py

示例12: __init__

# 需要导入模块: from tornado import ioloop [as 别名]
# 或者: from tornado.ioloop import PeriodicCallback [as 别名]
def __init__(self, *args, **kwargs):
        super(MultiplexPOSIXIOLoop, self).__init__(*args, **kwargs)
        from tornado import ioloop
        self.terminating = False
        self.sent_sigint = False
        self.shell_command = ['/bin/sh', '-c']
        self.use_shell = True # Controls whether or not we wrap with the above
        self.env = {}
        self.io_loop = ioloop.IOLoop.current() # Monitors child for activity
        #self.io_loop.set_blocking_signal_threshold(2, self._blocked_io_handler)
        #signal.signal(signal.SIGALRM, self._blocked_io_handler)
        self.reenable_timeout = None
        interval = 100 # A 0.1 second interval should be fast enough
        self.scheduler = ioloop.PeriodicCallback(self._timeout_checker,interval)
        self.exitstatus = None
        self._checking_patterns = False
        self.read_timeout = datetime.now()
        self.capture_limit = -1 # Huge reads by default
        self.restore_rate = None 
开发者ID:jimmy201602,项目名称:django-gateone,代码行数:21,代码来源:termio.py

示例13: _timeout_checker

# 需要导入模块: from tornado import ioloop [as 别名]
# 或者: from tornado.ioloop import PeriodicCallback [as 别名]
def _timeout_checker(self):
        """
        Runs `timeout_check` and if there are no more non-sticky
        patterns in :attr:`self._patterns`, stops :attr:`scheduler`.
        """
        if not self._checking_patterns:
            self._checking_patterns = True
            remaining_patterns = self.timeout_check()
            if not remaining_patterns:
                # No reason to keep the PeriodicCallback going
                logging.debug("Stopping self.scheduler (no remaining patterns)")
                try:
                    self.scheduler.stop()
                except AttributeError:
                # Now this is a neat trick:  The way IOLoop works with its
                # stack_context thingamabob the scheduler doesn't actualy end up
                # inside the MultiplexPOSIXIOLoop instance inside of this
                # instance of _timeout_checker() *except* inside the main
                # thread.  It is absolutely wacky but it works and works well :)
                    pass
            self._checking_patterns = False 
开发者ID:jimmy201602,项目名称:django-gateone,代码行数:23,代码来源:termio.py

示例14: __init__

# 需要导入模块: from tornado import ioloop [as 别名]
# 或者: from tornado.ioloop import PeriodicCallback [as 别名]
def __init__(self, io_loop):
        # Sessions
        self.sess_active = 0

        # Avoid circular reference
        self.sess_transports = dict()

        # Connections
        self.conn_active = 0
        self.conn_ps = MovingAverage()

        # Packets
        self.pack_sent_ps = MovingAverage()
        self.pack_recv_ps = MovingAverage()

        self._callback = ioloop.PeriodicCallback(self._update,
                                                 1000,
                                                 io_loop)
        self._callback.start() 
开发者ID:AstroPrint,项目名称:AstroBox,代码行数:21,代码来源:stats.py

示例15: start

# 需要导入模块: from tornado import ioloop [as 别名]
# 或者: from tornado.ioloop import PeriodicCallback [as 别名]
def start(self):
        wait_sec = 10
        while True:
            try:
                self.stream = yield TCPClient().connect(self.host, self.port)
                break
            except iostream.StreamClosedError:
                logger.error("connect error and again")
                yield gen.sleep(wait_sec)
                wait_sec = (wait_sec if (wait_sec >= 60) else (wait_sec * 2))
            
        self.send_heart_beat()
        self.heartbeat_callback = PeriodicCallback(self.send_heart_beat, 1000 * HEARTBEAT_TIMEOUT)
        self.heartbeat_callback.start()                 # start scheduler
        self.login()
        self.stream.read_bytes(16, self.__recv_header) 
开发者ID:wechat-tests,项目名称:PyMicroChat,代码行数:18,代码来源:client_tornado.py


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