def get_future_loop(fut: asyncio.Future) -> asyncio.AbstractEventLoop: try: # Future.get_loop() was added in Python 3.7. return fut.get_loop() except AttributeError: # Access private '_loop' attribute in asyncio.Future implementation as fallback. return fut._loop
def get_loop(future: asyncio.Future) -> asyncio.AbstractEventLoop: if sys.version_info >= (3, 7): return future.get_loop() else: return future._loop
def _set_future_exception(future: asyncio.Future, exc: BaseException) -> None: future.get_loop().call_soon_threadsafe(future.set_exception, exc)
def setter(f: asyncio.Future): sleep(1) f.get_loop().call_soon_threadsafe(partial(f.set_result, None)) print("Setting done")
def _set_future_result(future: asyncio.Future, result: Any) -> None: future.get_loop().call_soon_threadsafe(future.set_result, result)