def run_sync(self, function: typing.Callable, timeout: int=5):
"""
Execute the async function and return its result. This method takes care of starting and stopping the ioloop. The
main use for this function is to use the inmanta internal rpc to communicate with the server.
:param function: The async function to execute. This function should return a yieldable object.
:param timeout: A timeout for the async function.
:return: The result of the async call.
:raises ConnectionRefusedError: When the function timeouts this exception is raised.
"""
from tornado.ioloop import IOLoop, TimeoutError
try:
return IOLoop.current().run_sync(function, timeout)
except TimeoutError:
raise ConnectionRefusedError()
评论列表
文章目录