本文整理汇总了Python中tornado.ioloop.IOLoop.make_current方法的典型用法代码示例。如果您正苦于以下问题:Python IOLoop.make_current方法的具体用法?Python IOLoop.make_current怎么用?Python IOLoop.make_current使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tornado.ioloop.IOLoop
的用法示例。
在下文中一共展示了IOLoop.make_current方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: loop
# 需要导入模块: from tornado.ioloop import IOLoop [as 别名]
# 或者: from tornado.ioloop.IOLoop import make_current [as 别名]
def loop():
IOLoop.clear_instance()
loop = IOLoop()
loop.make_current()
yield loop
loop.stop()
loop.close()
示例2: run_worker
# 需要导入模块: from tornado.ioloop import IOLoop [as 别名]
# 或者: from tornado.ioloop.IOLoop import make_current [as 别名]
def run_worker(q, ip, center_ip, center_port, ncores, nanny_port,
local_dir, services):
""" Function run by the Nanny when creating the worker """
from distributed import Worker
from tornado.ioloop import IOLoop
IOLoop.clear_instance()
loop = IOLoop()
loop.make_current()
worker = Worker(center_ip, center_port, ncores=ncores, ip=ip,
service_ports={'nanny': nanny_port}, local_dir=local_dir,
services=services)
@gen.coroutine
def start():
try:
yield worker._start()
except Exception as e:
logger.exception(e)
q.put(e)
else:
assert worker.port
q.put({'port': worker.port, 'dir': worker.local_dir})
loop.add_callback(start)
loop.start()
示例3: test_instance_pool
# 需要导入模块: from tornado.ioloop import IOLoop [as 别名]
# 或者: from tornado.ioloop.IOLoop import make_current [as 别名]
def test_instance_pool(self):
instance1 = _Instance()
instance2 = _Instance()
pool = InstancePool([instance1, instance2])
pool.increment()
pool.increment()
self.assertEquals(instance1.value(), 1)
self.assertEquals(instance2.value(), 1)
pool.transaction(lambda i: i.increment())
pool.transaction(lambda i: i.increment())
self.assertEquals(instance1.value(), 2)
self.assertEquals(instance2.value(), 2)
@coroutine
def yield_tasks():
self.assertEquals((yield pool.await().increment()), 3)
self.assertEquals((yield pool.await().increment()), 3)
self.assertEquals(instance1.value(), 3)
self.assertEquals(instance2.value(), 3)
self.assertEquals((yield pool.await_transaction(lambda i: i.increment())), 4)
self.assertEquals((yield pool.await_transaction(lambda i: i.increment())), 4)
loop = IOLoop()
loop.make_current()
loop.run_sync(yield_tasks)
self.assertEquals(instance1.value(), 4)
self.assertEquals(instance2.value(), 4)
示例4: run_worker
# 需要导入模块: from tornado.ioloop import IOLoop [as 别名]
# 或者: from tornado.ioloop.IOLoop import make_current [as 别名]
def run_worker(q, ip, center_ip, center_port, ncores, nanny_port,
worker_port, local_dir, services, name):
""" Function run by the Nanny when creating the worker """
from distributed import Worker # pragma: no cover
from tornado.ioloop import IOLoop # pragma: no cover
IOLoop.clear_instance() # pragma: no cover
loop = IOLoop() # pragma: no cover
loop.make_current() # pragma: no cover
worker = Worker(center_ip, center_port, ncores=ncores, ip=ip,
service_ports={'nanny': nanny_port}, local_dir=local_dir,
services=services, name=name) # pragma: no cover
@gen.coroutine # pragma: no cover
def start():
try: # pragma: no cover
yield worker._start(worker_port) # pragma: no cover
except Exception as e: # pragma: no cover
logger.exception(e) # pragma: no cover
q.put(e) # pragma: no cover
else:
assert worker.port # pragma: no cover
q.put({'port': worker.port, 'dir': worker.local_dir}) # pragma: no cover
loop.add_callback(start) # pragma: no cover
with ignoring(KeyboardInterrupt):
loop.start() # pragma: no cover
示例5: test_flexx_in_thread4
# 需要导入模块: from tornado.ioloop import IOLoop [as 别名]
# 或者: from tornado.ioloop.IOLoop import make_current [as 别名]
def test_flexx_in_thread4():
""" Test threading starting server in other thread where it is created.
"""
res = []
loop = IOLoop()
loop.make_current()
app.create_server()
def try_start():
try:
app.stop()
app.start()
except RuntimeError:
res.append('start-fail')
else:
res.append('start-ok')
def main():
app.create_server()
try_start()
# Try to start server that was created in other thread -> fail
t = threading.Thread(target=try_start)
t.start()
t.join()
# Try to start in same thread as created -> ok
t = threading.Thread(target=main)
t.start()
t.join()
assert res == ['start-fail', 'start-ok']
示例6: test_flexx_in_thread1
# 需要导入模块: from tornado.ioloop import IOLoop [as 别名]
# 或者: from tornado.ioloop.IOLoop import make_current [as 别名]
def test_flexx_in_thread1():
""" Test threading and ioloop selection.
"""
def main():
loop2.make_current()
app.create_server()
# Create 3 loops, nr 2 is made current in the thread
loop1 = IOLoop()
loop2 = IOLoop()
loop3 = IOLoop()
loop1.make_current()
server1 = app.create_server()
t = threading.Thread(target=main)
t.start()
t.join()
server2 = app.current_server() # still current as set by the thread
loop3.make_current()
server3 = app.create_server()
assert server1._loop is loop1
assert server2._loop is loop2
assert server3._loop is loop3
示例7: test_rebinding_ioloop
# 需要导入模块: from tornado.ioloop import IOLoop [as 别名]
# 或者: from tornado.ioloop.IOLoop import make_current [as 别名]
def test_rebinding_ioloop():
""" Test recreating server objects, and its binding to the current ioloop.
"""
res = []
def add_res(i):
res.append(i)
# Create new ioloop
loop = IOLoop()
loop.make_current()
# Create new flexx server, which binds to that loop
server1 = app.create_server()
assert server1 is app.current_server()
#
assert loop is server1._loop
# Create new ioloop
loop = IOLoop()
loop.make_current()
# This is a new loop
assert loop is not server1._loop
# Create new flexx server, which binds to that loop
server2 = app.create_server()
assert server2 is app.current_server()
assert server1 is not server2
#
assert loop is server2._loop
示例8: test__yield_for_all_futures
# 需要导入模块: from tornado.ioloop import IOLoop [as 别名]
# 或者: from tornado.ioloop.IOLoop import make_current [as 别名]
def test__yield_for_all_futures():
loop = IOLoop()
loop.make_current()
@gen.coroutine
def several_steps():
value = 0
value += yield async_value(1)
value += yield async_value(2)
value += yield async_value(3)
raise gen.Return(value)
result = {}
def on_done(future):
result["value"] = future.result()
loop.stop()
loop.add_future(yield_for_all_futures(several_steps()), on_done)
try:
loop.start()
except KeyboardInterrupt as e:
print("keyboard interrupt")
assert 6 == result["value"]
loop.close()
示例9: run_worker_fork
# 需要导入模块: from tornado.ioloop import IOLoop [as 别名]
# 或者: from tornado.ioloop.IOLoop import make_current [as 别名]
def run_worker_fork(q, ip, scheduler_ip, scheduler_port, ncores, nanny_port,
worker_port, local_dir, services, name, memory_limit):
""" Function run by the Nanny when creating the worker """
from distributed import Worker # pragma: no cover
from tornado.ioloop import IOLoop # pragma: no cover
IOLoop.clear_instance() # pragma: no cover
loop = IOLoop() # pragma: no cover
loop.make_current() # pragma: no cover
worker = Worker(scheduler_ip, scheduler_port, ncores=ncores, ip=ip,
service_ports={'nanny': nanny_port}, local_dir=local_dir,
services=services, name=name, memory_limit=memory_limit,
loop=loop) # pragma: no cover
@gen.coroutine # pragma: no cover
def start():
try: # pragma: no cover
yield worker._start(worker_port) # pragma: no cover
except Exception as e: # pragma: no cover
logger.exception(e) # pragma: no cover
q.put(e) # pragma: no cover
else:
assert worker.port # pragma: no cover
q.put({'port': worker.port, 'dir': worker.local_dir}) # pragma: no cover
loop.add_callback(start) # pragma: no cover
try:
loop.start() # pragma: no cover
finally:
loop.stop()
loop.close(all_fds=True)
示例10: XDebugServer
# 需要导入模块: from tornado.ioloop import IOLoop [as 别名]
# 或者: from tornado.ioloop.IOLoop import make_current [as 别名]
class XDebugServer(TCPServer):
"""Class to listen for xdebug requests"""
def __init__(self):
"""Constructor """
self.ioloop = IOLoop()
super(XDebugServer, self).__init__(io_loop=self.ioloop)
self.listen(9000)
# this is for cross thread communication
self.inport = Queue()
self.outport = Queue()
self._xdebug_connection = None
def listenfunc():
self.ioloop.make_current()
self.ioloop.start()
self.ioloop.close(all_fds=True)
self.listener_thread = threading.Thread(target=listenfunc)
self.listener_thread.daemon = True
self.listener_thread.start()
def handle_stream(self, stream, address):
"""Handle a connection
Only one connection at a time, for now
:stream: @todo
:address: @todo
:returns: @todo
"""
self._xdebug_connection = XDebugConnection(self, stream, address)
def run_command(self, command, data=None):
"""Send status
:returns: @todo
"""
self.inport.put("{} -i 1\0".format(str(command)))
return self.outport.get()
def stop(self):
"""Stop tornado event loop
:returns: @todo
"""
self.ioloop.stop()
self.listener_thread.join()
del self.ioloop
del self.listener_thread
示例11: run_server
# 需要导入模块: from tornado.ioloop import IOLoop [as 别名]
# 或者: from tornado.ioloop.IOLoop import make_current [as 别名]
def run_server(port, daemon='start'):
application = tornado.web.Application([
(r"/", TestHandler, {'port': port}),
])
ioloop = IOLoop()
ioloop.make_current()
SERVER_LOOPS.append(ioloop)
application.listen(port)
ioloop.start()
示例12: pristine_loop
# 需要导入模块: from tornado.ioloop import IOLoop [as 别名]
# 或者: from tornado.ioloop.IOLoop import make_current [as 别名]
def pristine_loop():
IOLoop.clear_instance()
loop = IOLoop()
loop.make_current()
try:
yield loop
finally:
loop.close(all_fds=True)
IOLoop.clear_instance()
示例13: _run
# 需要导入模块: from tornado.ioloop import IOLoop [as 别名]
# 或者: from tornado.ioloop.IOLoop import make_current [as 别名]
def _run():
io_loop = IOLoop()
io_loop.make_current()
io_loop.add_callback(lambda : evt.set())
with mock.patch.dict(os.environ, env):
app = self._app = MockSingleUserServer()
app.initialize(args)
app.start()
示例14: _atexit
# 需要导入模块: from tornado.ioloop import IOLoop [as 别名]
# 或者: from tornado.ioloop.IOLoop import make_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)
示例15: atexit
# 需要导入模块: from tornado.ioloop import IOLoop [as 别名]
# 或者: from tornado.ioloop.IOLoop import make_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)