本文整理匯總了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)