diff options
| author | Alexandre Flament <alex@al-f.net> | 2021-05-05 18:33:16 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-05-05 18:33:16 +0200 |
| commit | 5b13786abb194dba3e562854de8fbb5a3fe8c2df (patch) | |
| tree | 50002f4c1c31d7e93897b70bc8a8aac946df0b6a /searx/search/processors/online.py | |
| parent | d36adfa59f242a8775ad74245c696d62b7727a36 (diff) | |
| parent | fa0d05c3131041eb44542e0b505eaed1833bf86e (diff) | |
Merge pull request #58 from searxng/mod-multithreading
[mod] multithreading only in searx.search.* packages
Diffstat (limited to 'searx/search/processors/online.py')
| -rw-r--r-- | searx/search/processors/online.py | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/searx/search/processors/online.py b/searx/search/processors/online.py index 93a9c6cbf..48a514e8a 100644 --- a/searx/search/processors/online.py +++ b/searx/search/processors/online.py @@ -5,7 +5,7 @@ """ -from time import time +from timeit import default_timer import asyncio import httpx @@ -40,6 +40,15 @@ class OnlineProcessor(EngineProcessor): engine_type = 'online' + def initialize(self): + # set timeout for all HTTP requests + searx.network.set_timeout_for_thread(self.engine.timeout, start_time=default_timer()) + # reset the HTTP total time + searx.network.reset_time_for_thread() + # set the network + searx.network.set_context_network_name(self.engine_name) + super().initialize() + def get_params(self, search_query, engine_category): params = super().get_params(search_query, engine_category) if params is None: @@ -139,7 +148,7 @@ class OnlineProcessor(EngineProcessor): self.handle_exception(result_container, e, suspend=True) logger.error("engine {0} : HTTP requests timeout" "(search duration : {1} s, timeout: {2} s) : {3}" - .format(self.engine_name, time() - start_time, + .format(self.engine_name, default_timer() - start_time, timeout_limit, e.__class__.__name__)) except (httpx.HTTPError, httpx.StreamError) as e: @@ -147,7 +156,7 @@ class OnlineProcessor(EngineProcessor): self.handle_exception(result_container, e, suspend=True) logger.exception("engine {0} : requests exception" "(search duration : {1} s, timeout: {2} s) : {3}" - .format(self.engine_name, time() - start_time, + .format(self.engine_name, default_timer() - start_time, timeout_limit, e)) except SearxEngineCaptchaException as e: |