def run_async(func, *args, **kwargs): if not inspect.iscoroutinefunction(func) and not gen.is_coroutine_function( func): fu = registry.executor_pool().submit(func, *args, **kwargs) fu = to_tornado_future(fu) else: fu = func(*args, **kwargs) return gen.convert_yielded(fu)
def adapt_result(self, result): while True: if isinstance(result, pydle.Future): result = yield result elif asyncio.iscoroutine(result) or isinstance(result, asyncio.Future): result = yield to_tornado_future( asyncio.ensure_future(result, loop=self.eventloop.io_loop.asyncio_loop) ) else: return result
def wrapper(*args, **kwargs): return to_tornado_future(ensure_future(func(*args, **kwargs)))
def _run_in_executor(self, func, *args, **kwargs): return to_tornado_future(self._executor.submit(func, *args, **kwargs))
def delay_task(func, callback=None, *args, **kw): asynfutu = executor.submit(func, *args, **kw) if callback: tonafutu = to_tornado_future(asynfutu) ioloop = tornado.ioloop.IOLoop.current() ioloop.add_future(tonafutu, callback)