當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。