示例#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
示例#2
0
def Loop():
    loop = asyncio.get_event_loop_policy().new_event_loop()
    asyncio.set_event_loop(loop)
    try:
        yield loop
    finally:
        loop.close()
示例#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)
示例#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)
        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)
示例#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()
示例#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()
示例#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()
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()
示例#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)
示例#11
0
 def tearDown(self):
     policy = asyncio.get_event_loop_policy()
     self.loop.close()
     policy.set_event_loop(None)
     super(SubprocessProactorTests, self).tearDown()
示例#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)
示例#13
0
 def tearDown(self):
     policy = asyncio.get_event_loop_policy()
     policy.set_child_watcher(None)
     self.loop.close()
     super(SubprocessWatcherMixin, self).tearDown()
示例#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)