Python tornado.ioloop.add_timeout() Examples

The following are 11 code examples of tornado.ioloop.add_timeout(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module tornado.ioloop , or try the search function .
Example #1
Source File: test_pool.py    From tornadis with MIT License 6 votes vote down vote up
def test_get_client2(self):
        c = ClientPool(max_size=2)
        client1 = yield c.get_connected_client()
        self.assertTrue(isinstance(client1, Client))
        client2 = yield c.get_connected_client()
        self.assertTrue(isinstance(client2, Client))
        ioloop = tornado.ioloop.IOLoop.instance()
        deadline = time.time() + 1
        cb = functools.partial(self._test_get_client2_cb, c, client1)
        self._test_get_client2_cb_called = False
        ioloop.add_timeout(deadline, cb)
        client3 = yield c.get_connected_client()
        self.assertTrue(self._test_get_client2_cb_called)
        self.assertTrue(client1 == client3)
        c.release_client(client2)
        c.release_client(client3)
        c.destroy() 
Example #2
Source File: init.py    From RobotAIEngine with Apache License 2.0 6 votes vote down vote up
def shutdown(ioloop, server):
    ''' 关闭server

    :param server: tornado.httpserver.HTTPServer
    '''
    logging.info(
        "HTTP interpreter service will shutdown in %ss...", 1)
    server.stop()

    deadline = time.time() + 1

    def stop_loop():
        ''' 尝试关闭loop
        '''
        now = time.time()
        if now < deadline and (ioloop._callbacks or ioloop._timeouts):
            ioloop.add_timeout(now + 1, stop_loop)
        else:
            # 处理完现有的 callback 和 timeout 后
            ioloop.stop()
            logging.info('Shutdown!')

    stop_loop() 
Example #3
Source File: __init__.py    From bugbuzz-python with MIT License 5 votes vote down vote up
def timeout(self, delay, callback):
        ioloop.add_timeout(time.time() + float(delay), callback) 
Example #4
Source File: __init__.py    From bugbuzz-python with MIT License 5 votes vote down vote up
def timeout(self, delay, callback):
        ioloop.add_timeout(time.time() + float(delay), callback) 
Example #5
Source File: backend_webagg.py    From Computable with MIT License 5 votes vote down vote up
def _timer_start(self):
        self._timer_stop()
        if self._single:
            ioloop = tornado.ioloop.IOLoop.instance()
            self._timer = ioloop.add_timeout(
                datetime.timedelta(milliseconds=self.interval),
                self._on_timer)
        else:
            self._timer = tornado.ioloop.PeriodicCallback(
                self._on_timer,
                self.interval)
        self._timer.start() 
Example #6
Source File: backend_webagg.py    From Computable with MIT License 5 votes vote down vote up
def draw_idle(self):
        if self._pending_draw is None:
            ioloop = tornado.ioloop.IOLoop.instance()
            self._pending_draw = ioloop.add_timeout(
                datetime.timedelta(milliseconds=50),
                self._draw_idle_callback) 
Example #7
Source File: backend_webagg.py    From matplotlib-4-abaqus with MIT License 5 votes vote down vote up
def _timer_start(self):
        self._timer_stop()
        if self._single:
            ioloop = tornado.ioloop.IOLoop.instance()
            self._timer = ioloop.add_timeout(
                datetime.timedelta(milliseconds=self.interval),
                self._on_timer)
        else:
            self._timer = tornado.ioloop.PeriodicCallback(
                self._on_timer,
                self.interval)
        self._timer.start() 
Example #8
Source File: backend_webagg.py    From matplotlib-4-abaqus with MIT License 5 votes vote down vote up
def draw_idle(self):
        if self._pending_draw is None:
            ioloop = tornado.ioloop.IOLoop.instance()
            self._pending_draw = ioloop.add_timeout(
                datetime.timedelta(milliseconds=50),
                self._draw_idle_callback) 
Example #9
Source File: backend_nbagg.py    From neural-network-animation with MIT License 5 votes vote down vote up
def _timer_start(self):
        import datetime
        self._timer_stop()
        if self._single:
            ioloop = tornado.ioloop.IOLoop.instance()
            self._timer = ioloop.add_timeout(
                datetime.timedelta(milliseconds=self.interval),
                self._on_timer)
        else:
            self._timer = tornado.ioloop.PeriodicCallback(
                self._on_timer,
                self.interval)
        self._timer.start() 
Example #10
Source File: backend_nbagg.py    From ImageFusion with MIT License 5 votes vote down vote up
def _timer_start(self):
        import datetime
        self._timer_stop()
        if self._single:
            ioloop = tornado.ioloop.IOLoop.instance()
            self._timer = ioloop.add_timeout(
                datetime.timedelta(milliseconds=self.interval),
                self._on_timer)
        else:
            self._timer = tornado.ioloop.PeriodicCallback(
                self._on_timer,
                self.interval)
        self._timer.start() 
Example #11
Source File: web_gui_server.py    From openhtf with Apache License 2.0 5 votes vote down vote up
def stop(self):
    self.server.stop()
    ioloop = tornado.ioloop.IOLoop.instance()
    ioloop.add_timeout(time.time() + _SERVER_SHUTDOWN_BUFFER_S, ioloop.stop)