本文整理汇总了Python中tornado.ioloop.IOLoop.clear_current方法的典型用法代码示例。如果您正苦于以下问题:Python IOLoop.clear_current方法的具体用法?Python IOLoop.clear_current怎么用?Python IOLoop.clear_current使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tornado.ioloop.IOLoop
的用法示例。
在下文中一共展示了IOLoop.clear_current方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init_process
# 需要导入模块: from tornado.ioloop import IOLoop [as 别名]
# 或者: from tornado.ioloop.IOLoop import clear_current [as 别名]
def init_process(self):
# IOLoop cannot survive a fork or be shared across processes
# in any way. When multiple processes are being used, each process
# should create its own IOLoop. We should clear current IOLoop
# if exists before os.fork.
IOLoop.clear_current()
super().init_process()
示例2: tearDown
# 需要导入模块: from tornado.ioloop import IOLoop [as 别名]
# 或者: from tornado.ioloop.IOLoop import clear_current [as 别名]
def tearDown(self):
self.db.close()
try:
os.remove(self.temp_db)
except:
pass
IOLoop.clear_current()
示例3: test_sync_closed_loop
# 需要导入模块: from tornado.ioloop import IOLoop [as 别名]
# 或者: from tornado.ioloop.IOLoop import clear_current [as 别名]
def test_sync_closed_loop():
loop = IOLoop.current()
loop.close()
IOLoop.clear_current()
IOLoop.clear_instance()
with pytest.raises(RuntimeError) as exc_info:
sync(loop, inc, 1)
exc_info.match("IOLoop is clos(ed|ing)")
示例4: start
# 需要导入模块: from tornado.ioloop import IOLoop [as 别名]
# 或者: from tornado.ioloop.IOLoop import clear_current [as 别名]
def start(self):
self.client = TCPClient()
self.pcb = PeriodicCallback(self.send, 1000.0 / self.n)
self.pcb.start()
IOLoop.current().call_later(self.duration + 0.5, self.stop)
IOLoop.current().start()
IOLoop.clear_current()
示例5: start
# 需要导入模块: from tornado.ioloop import IOLoop [as 别名]
# 或者: from tornado.ioloop.IOLoop import clear_current [as 别名]
def start(self):
try:
app = ftApplication(self.HANDLERS)
server = HTTPServer(app)
server.bind(self.PORT)
server.start(self.PROCESS_NUM)
IOLoop.clear_current().start()
except Exception, msg:
print "[tornado server start Exceptions : %s]" % msg
示例6: atexit
# 需要导入模块: from tornado.ioloop import IOLoop [as 别名]
# 或者: from tornado.ioloop.IOLoop import clear_current [as 别名]
def atexit(self):
"""atexit callback"""
if self._atexit_ran:
return
self._atexit_ran = True
# run the cleanup step (in a new loop, because the interrupted one is unclean)
IOLoop.clear_current()
loop = IOLoop()
loop.make_current()
loop.run_sync(self.cleanup)
示例7: _atexit
# 需要导入模块: from tornado.ioloop import IOLoop [as 别名]
# 或者: from tornado.ioloop.IOLoop import clear_current [as 别名]
def _atexit(self):
if self._atexit_ran:
return
self._atexit_ran = True
self._stats_job.stop()
IOLoop.clear_current()
loop = IOLoop()
loop.make_current()
loop.run_sync(self._cleanup)
示例8: start
# 需要导入模块: from tornado.ioloop import IOLoop [as 别名]
# 或者: from tornado.ioloop.IOLoop import clear_current [as 别名]
def start(self):
old_current = IOLoop.current(instance=False)
try:
self._setup_logging()
self.make_current()
self.reactor.run()
finally:
if old_current is None:
IOLoop.clear_current()
else:
old_current.make_current()
示例9: start
# 需要导入模块: from tornado.ioloop import IOLoop [as 别名]
# 或者: from tornado.ioloop.IOLoop import clear_current [as 别名]
def start(self):
old_current = IOLoop.current(instance=False)
try:
self._setup_logging()
self.make_current()
self.asyncio_loop.run_forever()
finally:
if old_current is None:
IOLoop.clear_current()
else:
old_current.make_current()
示例10: wrapper
# 需要导入模块: from tornado.ioloop import IOLoop [as 别名]
# 或者: from tornado.ioloop.IOLoop import clear_current [as 别名]
def wrapper(*args, **kwargs):
loop = None
try:
IOLoop.clear_current()
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
loop.run_until_complete(fn(*args, **kwargs))
finally:
if loop is not None:
loop.close()
IOLoop.clear_current()
asyncio.set_event_loop(None)
示例11: single_run_ws
# 需要导入模块: from tornado.ioloop import IOLoop [as 别名]
# 或者: from tornado.ioloop.IOLoop import clear_current [as 别名]
def single_run_ws(url, delay=0, size=0, msgs=1):
"""Time a single websocket run"""
buf = hexlify(os.urandom(size // 2)).decode('ascii')
msg = json.dumps({'delay': delay, 'data': buf})
async def go():
ws = await websocket_connect(url.replace('http', 'ws') + '/ws')
for i in range(msgs):
ws.write_message(msg)
await ws.read_message()
asyncio.set_event_loop(asyncio.new_event_loop())
IOLoop.clear_current()
loop = IOLoop(make_current=True)
loop.run_sync(go)
示例12: pristine_loop
# 需要导入模块: from tornado.ioloop import IOLoop [as 别名]
# 或者: from tornado.ioloop.IOLoop import clear_current [as 别名]
def pristine_loop():
IOLoop.clear_instance()
IOLoop.clear_current()
loop = IOLoop()
loop.make_current()
assert IOLoop.current() is loop
try:
yield loop
finally:
try:
loop.close(all_fds=True)
except (KeyError, ValueError):
pass
IOLoop.clear_instance()
IOLoop.clear_current()
示例13: start
# 需要导入模块: from tornado.ioloop import IOLoop [as 别名]
# 或者: from tornado.ioloop.IOLoop import clear_current [as 别名]
def start(self):
old_current = IOLoop.current(instance=False)
try:
old_asyncio = asyncio.get_event_loop()
except RuntimeError:
old_asyncio = None
try:
self._setup_logging()
self.make_current()
# This is automatic in 3.5, but must be done manually in 3.4.
asyncio.set_event_loop(self.asyncio_loop)
self.asyncio_loop.run_forever()
finally:
if old_current is None:
IOLoop.clear_current()
else:
old_current.make_current()
asyncio.set_event_loop(old_asyncio)
示例14: run
# 需要导入模块: from tornado.ioloop import IOLoop [as 别名]
# 或者: from tornado.ioloop.IOLoop import clear_current [as 别名]
def run():
io_loop = IOLoop(make_current=True)
app = Application([("/", RootHandler)])
port = random.randrange(options.min_port, options.max_port)
app.listen(port, address='127.0.0.1')
signal.signal(signal.SIGCHLD, handle_sigchld)
args = ["ab"]
args.extend(["-n", str(options.n)])
args.extend(["-c", str(options.c)])
if options.keepalive:
args.append("-k")
if options.quiet:
# just stops the progress messages printed to stderr
args.append("-q")
args.append("http://127.0.0.1:%d/" % port)
subprocess.Popen(args)
io_loop.start()
io_loop.close()
io_loop.clear_current()
示例15: run_server
# 需要导入模块: from tornado.ioloop import IOLoop [as 别名]
# 或者: from tornado.ioloop.IOLoop import clear_current [as 别名]
def run_server(port, password, dbfile):
"""Start up the HTTP server. If Tornado is available it will be used, else
fall back to the Flask debug server.
"""
app.config['PASSWORD'] = password
app.config['DBFILE'] = dbfile
if USE_TORNADO:
# When running inside an IPython Notebook, the IOLoop
# can inherit a stale instance from the parent process,
# so clear that.
# https://github.com/adamgreig/sheepdog/issues/15
# Thanks @minrk!
if hasattr(IOLoop, '_instance'):
del IOLoop._instance
IOLoop.clear_current()
HTTPServer(WSGIContainer(app)).listen(port)
IOLoop.instance().start()
else:
app.run(host='0.0.0.0', port=port)