Example #1
0
def install_loop():
    """Install and return the global ZMQEventLoop
    registers the loop with asyncio.set_event_loop
    """
    # check if tornado's IOLoop is already initialized to something other
    # than the pyzmq IOLoop instance:
    assert (not IOLoop.initialized()) or \
        IOLoop.instance() is AsyncIOMainLoop.instance(), "tornado IOLoop already initialized"

    # First, set asyncio to use ZMQEventLoop (ZMQSelector) as its loop
    asyncio.set_event_loop_policy(ZMQPolicy())
    # Next have tornado work on top of current asyncio loop
    AsyncIOMainLoop().install()