diff options
author | Adam Tauber <asciimoo@gmail.com> | 2015-10-31 14:40:59 +0100 |
---|---|---|
committer | Adam Tauber <asciimoo@gmail.com> | 2015-10-31 14:40:59 +0100 |
commit | 357fc47811a1de5a273622881574dbde23c7cb59 (patch) | |
tree | bb1c92cc8bac31d80ed1ec48d17d46f0668dc11a /searx/poolrequests.py | |
parent | 5d49c15f791c3b9297bb890b28643e6c50406f35 (diff) | |
download | searxng-357fc47811a1de5a273622881574dbde23c7cb59.tar.gz searxng-357fc47811a1de5a273622881574dbde23c7cb59.zip |
[fix] lock request pool generator
Diffstat (limited to 'searx/poolrequests.py')
-rw-r--r-- | searx/poolrequests.py | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/searx/poolrequests.py b/searx/poolrequests.py index c44bdc7e2..4761f6ae8 100644 --- a/searx/poolrequests.py +++ b/searx/poolrequests.py @@ -1,5 +1,7 @@ import requests + from itertools import cycle +from threading import RLock from searx import settings @@ -55,9 +57,10 @@ class SessionSinglePool(requests.Session): super(SessionSinglePool, self).__init__() # reuse the same adapters - self.adapters.clear() - self.mount('https://', next(https_adapters)) - self.mount('http://', next(http_adapters)) + with RLock(): + self.adapters.clear() + self.mount('https://', next(https_adapters)) + self.mount('http://', next(http_adapters)) def close(self): """Call super, but clear adapters since there are managed globaly""" @@ -67,7 +70,6 @@ class SessionSinglePool(requests.Session): def request(method, url, **kwargs): """same as requests/requests/api.py request(...) except it use SessionSinglePool and force proxies""" - global settings session = SessionSinglePool() kwargs['proxies'] = settings['outgoing'].get('proxies', None) response = session.request(method=method, url=url, **kwargs) |