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.
MIT License
927 stars 117 forks source link

Runtime warning due AsyncDDGS while using DDGS text method #183

Closed kspviswa closed 4 months ago

kspviswa commented 4 months ago

I need a synchronous call to my search. That's the reason I'm preferring to use DDGS instead of AsyncDDGS. But as per https://github.com/deedy5/duckduckgo_search/blob/9871eeb845c085405a22039f2624e992fba0568e/duckduckgo_search/duckduckgo_search.py#L13 , there is no such demarcation.

I'm actually using langchain's ddgs search wrapper : https://github.com/langchain-ai/langchain/blob/master/libs/community/langchain_community/utilities/duckduckgo_search.py#L47 , which clearly uses DDGS with with scope as suggested.

However, I'm seeing lot this (below) while running my app :

Task was destroyed but it is pending!
task: <Task pending name='Task-5' coro=<AsyncDDGS.__aexit__() running at </path/to>/.venv/lib/python3.12/site-packages/duckduckgo_search/duckduckgo_search_async.py:46>>
/opt/homebrew/Cellar/python@3.12/3.12.1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/base_events.py:709: RuntimeWarning: coroutine 'AsyncDDGS.__aexit__' was never awaited
  self._ready.clear()
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
Task was destroyed but it is pending!

I was puzzled why am I getting this since I never used AsyncDDGS but now its clear why. But still I couldn't understand how to get rid of this. Could you share any pointers?

deedy5 commented 4 months ago

Only when I call a func in search.py that uses DDGS, I'm seeing this error.

Can you show search.py?

kspviswa commented 4 months ago

Sure https://github.com/kspviswa/pyOllaMx/blob/main/search.py#L33

deedy5 commented 4 months ago

update to v4.4.1

pip install -U duckduckgo_search
kspviswa commented 4 months ago

If I run the code standalone, I don't see any issue. But If I run search.py along with the main.py, I'm seeing this error

There is no current event loop in thread 'Thread-79 (send)'

Can you please point me what am I missing? I'm not seeing this issue with v4.4 .