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
def Loop(): loop = asyncio.get_event_loop_policy().new_event_loop() asyncio.set_event_loop(loop) try: yield loop finally: loop.close()
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)
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)
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()
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()
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 setUp(self): super(TrolliusSocketTests, self).setUp() if asyncio is not None: policy = trollius.get_event_loop_policy() asyncio.set_event_loop_policy(policy)
def tearDown(self): policy = asyncio.get_event_loop_policy() self.loop.close() policy.set_event_loop(None) super(SubprocessProactorTests, self).tearDown()
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)
def tearDown(self): policy = asyncio.get_event_loop_policy() policy.set_child_watcher(None) self.loop.close() super(SubprocessWatcherMixin, self).tearDown()