ragas icon indicating copy to clipboard operation
ragas copied to clipboard

Please stop using deprecated/archived `nest_asyncio` package

Open dagardner-nv opened this issue 3 months ago • 4 comments

[x] I have checked the documentation and related resources and couldn't resolve my bug.

Describe the bug nest_asyncio has been archived by the owner for over a year now.

This has created problems with asyncio support in newer versions of Python and other packages which depend on these newer features. Specifically Python 3.12+ added an optional loop_factory parameter, however the patched version of asyncio.run from nest_asyncio's patched run method doesn't pass-through this keyword argument resulting in errors like:

> asyncio_run(amain(), loop_factory=get_loop_factory())
E TypeError: _patch_asyncio.<locals>.run() got an unexpected keyword argument 'loop_factory'

Ragas version: v0.2.15 (however this dependency exists in the main branch: https://github.com/explodinggradients/ragas/blob/main/pyproject.toml Python version: 3.12

Code to Reproduce Share code to reproduce the issue

Error trace

Expected behavior A clear and concise description of what you expected to happen.

Additional context Add any other context about the problem here.

dagardner-nv avatar Sep 05 '25 23:09 dagardner-nv

Thanks for raising the issue @dagardner-nv It's a valid concern. Do you've any suggestions as well?

anistark avatar Sep 06 '25 10:09 anistark

Considering a few options:

  1. Replace with anyio.
  2. Change approach to thread-based.

anistark avatar Sep 06 '25 10:09 anistark

@anistark anyio is interesting I wasn't familiar with it until you suggested it. I looked into this a bit, and unless I'm missing something I don't think it provides the needed functionality (with the default asyncio or trio backends).

This was my quick-test:

import anyio

class DoAsyncStuff:
    async def do_cool_stuff(self):
        print(self)

    async def get_info(self):
        return "Async Info"

    def __str__(self):
        return anyio.run(self.get_info, backend='asyncio')

def main():
    stuff = DoAsyncStuff()
    print("Should work")
    print(stuff)
    print("Won't work, can't call anyio.run from within a loop")
    anyio.run(stuff.do_cool_stuff, backend='asyncio')

if __name__ == '__main__':
    main()

dagardner-nv avatar Sep 10 '25 23:09 dagardner-nv

I've made a fork of nest-asyncio to fix support for Python 3.12 and 3.14: nest-asyncio2. Since it's also used in my own project, I'm going to maintain it for a long time. There is no behavior change on Python < 3.12, and it's already tested with https://github.com/NVIDIA/NeMo-Agent-Toolkit, https://github.com/pyvista/pyvista, https://github.com/Chaoses-Ib/ComfyScript, so it should be a safe replacement.

Chaoses-Ib avatar Nov 21 '25 08:11 Chaoses-Ib