def async_call(self, f: Callable[..., Any], *a: Any, **kw: Any) -> Any:
''' run a callback function on the main thread and return its
value (blocking). the callback receives 'self' as an argument.
'''
if not shutdown:
msg = 'running {} on main thread blocking'
self.log.debug2(lambda: msg.format(format_funcall(f.__name__, a, kw)))
result_fut = futures.Future() # type: futures.Future
@functools.wraps(f)
def cb() -> None:
result_fut.set_result(f(self, *a, **kw))
self._run_on_main_thread(cb)
result = result_fut.result()
self.log.debug2(lambda: f'async returns {result}')
return result
else:
return f(self, *a, **kw)
评论列表
文章目录