nest-asyncio2 v1.6.3
-
fix: not
run_close_loopby default on Python 3.12+ (Chaoses-Ib/ComfyScript#117, pyvista/pyvista#7938)See the following for details.
-
Add some pyvista tests
Leaked loop
Tip
TL;DR: Usually you don't need to worry about this. The biggest side effect is a ResourceWarning: unclosed event loop at exit on Python 3.12+ that is hidden by default.
If there is no existing event loop, patched asyncio.run() will create one but not close it afterwards. It will be reused later, so there will be at most one leaked loop.
asyncio.run() will always create and close the loop. But nest_asyncio (by accident or intentionally) missed it. As changing this behavior will break existing projects (e.g. ComfyScript, pyvista), nest-asyncio2 follows this behavior.
This will cause a ResourceWarning: unclosed event loop at exit on Python 3.12+, although it is hidden by default. (Note that if you call asyncio.get_event_loop() on the main thread without setting the loop before,
ResourceWarning is expected on Python 3.12~3.13, not caused by nest-asyncio2.)
If you want to follow asyncio.run()'s behavior and get rid of the ResourceWarning, you can set run_close_loop=True for all apply():
nest_asyncio2.apply(run_close_loop=True)Or pass loop_factory to asyncio.run() on Python 3.12+:
asyncio.run(..., loop_factory=asyncio.new_event_loop)nest-asyncio2 v2 may change run_close_loop to be enalbed by default.