Ejemplo n.º 1
0
def main(exit=True, install_tornado_bridge=True, prefer_trollius=True):
    if prefer_trollius:
        try:
            import asyncio
        except ImportError:
            pass
        else:
            asyncio.set_event_loop_policy(trollius.get_event_loop_policy())

    if install_tornado_bridge:
        tornado.platform.asyncio.AsyncIOMainLoop().install()

    arg_parser = AppArgumentParser()
    args = arg_parser.parse_args()

    builder = Builder(args)
    builder.build()

    application = builder.factory['Application']
    application.setup_signal_handlers()

    if args.debug_manhole:
        import manhole
        import wpull
        wpull.wpull_builder = builder
        manhole.install()

    exit_code = application.run_sync()

    if exit:
        sys.exit(exit_code)
    else:
        return exit_code
Ejemplo n.º 2
0
def Loop():
    loop = asyncio.get_event_loop_policy().new_event_loop()
    asyncio.set_event_loop(loop)
    try:
        yield loop
    finally:
        loop.close()
Ejemplo n.º 3
0
        def setUp(self):
            policy = asyncio.get_event_loop_policy()
            self.loop = policy.new_event_loop()
            self.set_event_loop(self.loop)

            watcher = self.Watcher()
            watcher.attach_loop(self.loop)
            policy.set_child_watcher(watcher)
            self.addCleanup(policy.set_child_watcher, None)
Ejemplo n.º 4
0
    def setUp(self):
        policy = trollius.get_event_loop_policy()

        asyncio.set_event_loop_policy(policy)
        self.addCleanup(asyncio.set_event_loop_policy, None)

        self.loop = policy.new_event_loop()
        self.addCleanup(self.loop.close)
        policy.set_event_loop(self.loop)
Ejemplo n.º 5
0
        def setUp(self):
            policy = asyncio.get_event_loop_policy()
            self.loop = policy.new_event_loop()

            # ensure that the event loop is passed explicitly in asyncio
            policy.set_event_loop(None)

            watcher = self.Watcher()
            watcher.attach_loop(self.loop)
            policy.set_child_watcher(watcher)
Ejemplo n.º 6
0
def center(loop=None):
    if loop is None:
        loop = asyncio.get_event_loop_policy().new_event_loop()
    port[0] += 1
    c = Center('127.0.0.1', port[0], '*', loop=loop, context=context)

    try:
        yield c
    finally:
        if c.status != 'closed':
            c.close()
Ejemplo n.º 7
0
def worker(metadata_port, port=3598, loop=None):
    if loop is None:
        loop = asyncio.get_event_loop_policy().new_event_loop()
    w = Worker('127.0.0.1',
               port,
               '*',
               'tcp://127.0.0.1:%d' % metadata_port,
               loop=loop)

    try:
        yield w
    finally:
        if w.status != 'closed':
            w.close()
Ejemplo n.º 8
0
def main():
    # use trollius event loop policy in asyncio
    policy = trollius.get_event_loop_policy()
    asyncio.set_event_loop_policy(policy)

    # create an event loop for the main thread: use Trollius event loop
    loop = trollius.get_event_loop()
    assert asyncio.get_event_loop() is loop

    print("[ asyncio coroutine called from trollius coroutine ]")
    coro1 = asyncio_noop()
    coro2 = asyncio_coroutine(coro1)
    res = loop.run_until_complete(trollius_coroutine(coro2))
    print("trollius coroutine result: %r" % res)
    print("")

    print("[ asyncio coroutine called from trollius coroutine ]")
    coro1 = trollius_noop()
    coro2 = trollius_coroutine(coro1)
    res = loop.run_until_complete(asyncio_coroutine(coro2))
    print("asyncio coroutine result: %r" % res)
    print("")

    loop.close()
Ejemplo n.º 9
0
def main():
    # use trollius event loop policy in asyncio
    policy = trollius.get_event_loop_policy()
    asyncio.set_event_loop_policy(policy)

    # create an event loop for the main thread: use Trollius event loop
    loop = trollius.get_event_loop()
    assert asyncio.get_event_loop() is loop

    print("[ asyncio coroutine called from trollius coroutine ]")
    coro1 = asyncio_noop()
    coro2 = asyncio_coroutine(coro1)
    res = loop.run_until_complete(trollius_coroutine(coro2))
    print("trollius coroutine result: %r" % res)
    print("")

    print("[ asyncio coroutine called from trollius coroutine ]")
    coro1 = trollius_noop()
    coro2 = trollius_coroutine(coro1)
    res = loop.run_until_complete(asyncio_coroutine(coro2))
    print("asyncio coroutine result: %r" % res)
    print("")

    loop.close()
Ejemplo n.º 10
0
 def setUp(self):
     super(TrolliusSocketTests, self).setUp()
     if asyncio is not None:
         policy = trollius.get_event_loop_policy()
         asyncio.set_event_loop_policy(policy)
Ejemplo n.º 11
0
 def tearDown(self):
     policy = asyncio.get_event_loop_policy()
     self.loop.close()
     policy.set_event_loop(None)
     super(SubprocessProactorTests, self).tearDown()
Ejemplo n.º 12
0
        def setUp(self):
            policy = asyncio.get_event_loop_policy()
            self.loop = asyncio.ProactorEventLoop()

            # ensure that the event loop is passed explicitly in asyncio
            policy.set_event_loop(None)
Ejemplo n.º 13
0
 def tearDown(self):
     policy = asyncio.get_event_loop_policy()
     policy.set_child_watcher(None)
     self.loop.close()
     super(SubprocessWatcherMixin, self).tearDown()
Ejemplo n.º 14
0
 def setUp(self):
     super(TrolliusSocketTests, self).setUp()
     if asyncio is not None:
         policy = trollius.get_event_loop_policy()
         asyncio.set_event_loop_policy(policy)