on master help sign in
[fix] lock request pool generator
commit357fc47811a1de5a273622881574dbde23c7cb59 authorAdam Tauber <asciimoo@gmail.com> dateSat 31 Oct 2015, 14:40 (11 years ago) parent5d49c15
1 file changed+6−4
searx/poolrequests.py+6−4
searx/poolrequests.py+6−4
@@ -1,5 +1,7 @@
11import requests
2+
23from itertools import cycle
4+from threading import RLock
35from searx import settings
46
57
@@ -55,9 +57,10 @@ class SessionSinglePool(requests.Session):
5557 super(SessionSinglePool, self).__init__()
5658
5759 # reuse the same adapters
58− self.adapters.clear()
59− self.mount('https://', next(https_adapters))
60− self.mount('http://', next(http_adapters))
60+ with RLock():
61+ self.adapters.clear()
62+ self.mount('https://', next(https_adapters))
63+ self.mount('http://', next(http_adapters))
6164
6265 def close(self):
6366 """Call super, but clear adapters since there are managed globaly"""
@@ -67,7 +70,6 @@ class SessionSinglePool(requests.Session):
6770
6871def request(method, url, **kwargs):
6972 """same as requests/requests/api.py request(...) except it use SessionSinglePool and force proxies"""
70− global settings
7173 session = SessionSinglePool()
7274 kwargs['proxies'] = settings['outgoing'].get('proxies', None)
7375 response = session.request(method=method, url=url, **kwargs)