浏览代码

[fix] lock request pool generator

Adam Tauber 9 年前
父节点
当前提交
357fc47811
共有 1 个文件被更改,包括 6 次插入4 次删除
  1. 6
    4
      searx/poolrequests.py

+ 6
- 4
searx/poolrequests.py 查看文件

@@ -1,5 +1,7 @@
1 1
 import requests
2
+
2 3
 from itertools import cycle
4
+from threading import RLock
3 5
 from searx import settings
4 6
 
5 7
 
@@ -55,9 +57,10 @@ class SessionSinglePool(requests.Session):
55 57
         super(SessionSinglePool, self).__init__()
56 58
 
57 59
         # 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))
61 64
 
62 65
     def close(self):
63 66
         """Call super, but clear adapters since there are managed globaly"""
@@ -67,7 +70,6 @@ class SessionSinglePool(requests.Session):
67 70
 
68 71
 def request(method, url, **kwargs):
69 72
     """same as requests/requests/api.py request(...) except it use SessionSinglePool and force proxies"""
70
-    global settings
71 73
     session = SessionSinglePool()
72 74
     kwargs['proxies'] = settings['outgoing'].get('proxies', None)
73 75
     response = session.request(method=method, url=url, **kwargs)