4 ms·
If I want to create a task that runs even after the function returns, ie "async def f(): asyncio.create_task(coro=10_second_coro.run()); return;" is there any w
by jarboot 4y ago
If I want to create a task that runs even after the function returns, ie "async def f(): asyncio.create_task(coro=10_second_coro.run()); return;" is there any way to mitigate this? Function-scoped set of tasks?
- jmholla 4y agoYour task is implicitly not function-scoped as you want it to survive exiting the function. What your doing here would be better architecturally done with threads. async is not a direct replacement for threading. But, you could also return the task object to the caller and have them manage it. There's also nothing async about your function, so you don't need the async or to await it.
- nhumrich 4y agoYes, read the last part of the included documentation and hold onto background tasks.