From 013636a064461d6639ca5a9ba25b3885021809ae Mon Sep 17 00:00:00 2001 From: deedy5 <65482418+deedy5@users.noreply.github.com> Date: Tue, 12 Mar 2024 23:03:31 +0300 Subject: [PATCH] AsyncDDGS: make _executor class variable --- duckduckgo_search/duckduckgo_search_async.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/duckduckgo_search/duckduckgo_search_async.py b/duckduckgo_search/duckduckgo_search_async.py index 59046dc..37d06b8 100644 --- a/duckduckgo_search/duckduckgo_search_async.py +++ b/duckduckgo_search/duckduckgo_search_async.py @@ -23,12 +23,13 @@ ) logger = logging.getLogger("duckduckgo_search.AsyncDDGS") -_SHARED_EXECUTOR = ThreadPoolExecutor() class AsyncDDGS: """DuckDuckgo_search async class to get search results from duckduckgo.com.""" + _executor = ThreadPoolExecutor() + def __init__( self, headers: Optional[Dict[str, str]] = None, @@ -247,7 +248,7 @@ async def _text_html_page(s: int, page: int) -> None: if b"No results." in resp_content: return - tree = await self._asession.loop.run_in_executor(_SHARED_EXECUTOR, html.document_fromstring, resp_content) + tree = await self._asession.loop.run_in_executor(self._executor, html.document_fromstring, resp_content) for e in tree.xpath("//div[h2]"): href = e.xpath("./a/@href") @@ -322,7 +323,7 @@ async def _text_lite_page(s: int, page: int) -> None: if b"No more results." in resp_content: return - tree = await self._asession.loop.run_in_executor(_SHARED_EXECUTOR, html.document_fromstring, resp_content) + tree = await self._asession.loop.run_in_executor(self._executor, html.document_fromstring, resp_content) data = zip(cycle(range(1, 5)), tree.xpath("//table[last()]//tr")) for i, e in data: