first of all, if you call time.sleep
, you will never end the event loop asyncio
, so the results will not be detected. instead of calling time.sleep
in do_it
you better do something like
asyncio.get_event_loop().run_until_complete(asyncio.sleep(0.1))
run_in_executor - . aync def create_task
asyncio
, -
async def run_long_thing(thing, *args):
try: await asyncio.get_event_loop().run_in_executor(None, thing, *args)
except:
def callback(future):
if future.exception():
run_in_executor:
future = asyncio.get_event_loop().run_in_executor(None, fun, *args)
future.add_done_callback(callback)
callback
, -. future.result()
, , future.exception()