Skip to content

Commit

Permalink
DDGS.__exit__(): add cancel pending tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
deedy5 committed Feb 23, 2024
1 parent 939ed63 commit 10dc371
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions duckduckgo_search/duckduckgo_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ def __enter__(self) -> "DDGS":
return self

def __exit__(self, exc_type, exc_val, exc_tb) -> None:
for task in asyncio.all_tasks(self._loop):
task.cancel()
self._loop.call_soon_threadsafe(self._loop.stop)
self._thread.join()
self._loop.close()

def _iter_over_async(self, async_gen):
"""Runs an asynchronous generator in a separate thread and yields results from the queue."""
Expand Down

0 comments on commit 10dc371

Please sign in to comment.