本文整理汇总了Python中tornado.ioloop.add_timeout方法的典型用法代码示例。如果您正苦于以下问题:Python ioloop.add_timeout方法的具体用法?Python ioloop.add_timeout怎么用?Python ioloop.add_timeout使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tornado.ioloop
的用法示例。
在下文中一共展示了ioloop.add_timeout方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_client2
# 需要导入模块: from tornado import ioloop [as 别名]
# 或者: from tornado.ioloop import add_timeout [as 别名]
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()
示例2: shutdown
# 需要导入模块: from tornado import ioloop [as 别名]
# 或者: from tornado.ioloop import add_timeout [as 别名]
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()
示例3: timeout
# 需要导入模块: from tornado import ioloop [as 别名]
# 或者: from tornado.ioloop import add_timeout [as 别名]
def timeout(self, delay, callback):
ioloop.add_timeout(time.time() + float(delay), callback)
示例4: _timer_start
# 需要导入模块: from tornado import ioloop [as 别名]
# 或者: from tornado.ioloop import add_timeout [as 别名]
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()
示例5: draw_idle
# 需要导入模块: from tornado import ioloop [as 别名]
# 或者: from tornado.ioloop import add_timeout [as 别名]
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)
示例6: _timer_start
# 需要导入模块: from tornado import ioloop [as 别名]
# 或者: from tornado.ioloop import add_timeout [as 别名]
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()
示例7: stop
# 需要导入模块: from tornado import ioloop [as 别名]
# 或者: from tornado.ioloop import add_timeout [as 别名]
def stop(self):
self.server.stop()
ioloop = tornado.ioloop.IOLoop.instance()
ioloop.add_timeout(time.time() + _SERVER_SHUTDOWN_BUFFER_S, ioloop.stop)