Skip to content
Advertisement

add task to running loop and run until complete

I have a function called from an async function without await, and my function needs to call async functions. I can do this with asyncio.get_running_loop().create_task(sleep()) but the run_until_complete at the top level doesn’t run until the new task is complete.

How do I get the event loop to run until the new task is complete?

I can’t make my function async because it’s not called with await.

I can’t change future or sleep. I’m only in control of in_control.

JavaScript

Advertisement

Answer

It appears that the package nest_asyncio will help you out here. I’ve also included in the example fetching the return value of the task.

JavaScript

Result:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement