-
Notifications
You must be signed in to change notification settings - Fork 0
Closed
Labels
enhancementNew feature or requestNew feature or request
Description
Currently I find myself taking care to ensure that our thirds-party dependencies which will apply the nest-asyncio patch on import, are lazily imported, allowing my own library to apply the nest_asyncio2 patch instead.
I find myself writing code like this:
# Make sure someone in our stack didn't already apply the older nest-asyncio patch
assert not hasattr(asyncio, "_nest_patched")
import nest_asyncio2
nest_asyncio2.apply()The main issue here is that I have no way to determine if nest_asyncio or nest_asyncio2 was applied.
Ideas:
-
In addition to the
_nest_patchedattribute, add a_nest2_patchedattribute. If both are set then we know the nest_asyncio2 patch was applied, if only_nest_patchedwas set then nest_asyncio was applied. -
Alternately since
nest-asyncioonly checks if the attribute exists, the value could be changed to2allowing for code like:
patched = getattr(asyncio, "_nest_patched", None)
if patched is None:
# apply patch
elif patched == 2:
# nest-asyncio2 is applied, we're good
elif patched is True:
logger.warn("Attempted to apply nest_asyncio2, but nest_asyncio was already applied")- Add an optional argument to raise an exception on apply if nest-asyncio was applied first something like:
def apply(loop=None, *, run_close_loop: bool = False, error_on_v1_patched: bool = False):
Edit by maintainer: related PR: NVIDIA/NeMo-Agent-Toolkit#1190
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request