handler.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:inmanta 作者: inmanta 项目源码 文件源码
def run_sync(self, func: typing.Callable) -> typing.Any:
        """
            Run a the given async function on the ioloop of the agent. It will block the current thread until the future
            resolves.

            :param func: A function that returns a yieldable future.
            :return: The result of the async function.
        """
        f = Future()

        def future_to_future(future):
            exc = future.exception()
            if exc is not None:
                f.set_exception(exc)
            else:
                f.set_result(future.result())

        def run():
            try:
                result = func()
                if result is not None:
                    from tornado.gen import convert_yielded
                    result = convert_yielded(result)
                    result.add_done_callback(future_to_future)
            except Exception as e:
                f.set_exception(e)
        self._ioloop.add_callback(run)

        return f.result()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号