deedy5 / duckduckgo_search

Search for words, documents, images, videos, news, maps and text translation using the DuckDuckGo.com search engine. Downloading files and images to a local hard drive.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Release 4.3 introduces breaking changes in downstream apps when ran as async

tdj28 opened this issue · comments

commented

Moving from 4.2 to 4.3 results in this error in CrewAI, for example: joaomdmoura/crewAI#193

RuntimeError: Cannot run the event loop while another loop is running

commented

Quick update, it appears to only happen when the search call is being called in an async function, unable to replicate with a normal function.

Error does not occur here:

from langchain_community.tools import DuckDuckGoSearchRun

search = DuckDuckGoSearchRun()

print(search.run("Obama's first name?"))

does occur here:

from langchain_community.tools import DuckDuckGoSearchRun
import asyncio

async def main():
    search = DuckDuckGoSearchRun()

    print(search.run("Obama's first name?"))


asyncio.run(main())
commented

This is the proper way to call this async:

from langchain_community.tools import DuckDuckGoSearchRun
import asyncio

async def main():
    search = DuckDuckGoSearchRun()

    result = await asyncio.to_thread(search.run, "Obama's first name?")
    print(result)


asyncio.run(main())

Which is partially documented in the README. I'll close this issue as this does not look like a bug in the code, but it will be a breaking change (from 4.2 to 4.3) for users who prior used async without properly awaiting, but the error is theirs. Hopefully this issue will help anyone else experiencing this.

The right way to use AsyncDDGS in asynchronous code.

Fixed in v4.4