[fix] lock request pool generator
This commit is contained in:
		
							parent
							
								
									5d49c15f79
								
							
						
					
					
						commit
						357fc47811
					
				| @ -1,5 +1,7 @@ | |||||||
| import requests | import requests | ||||||
|  | 
 | ||||||
| from itertools import cycle | from itertools import cycle | ||||||
|  | from threading import RLock | ||||||
| from searx import settings | from searx import settings | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @ -55,9 +57,10 @@ class SessionSinglePool(requests.Session): | |||||||
|         super(SessionSinglePool, self).__init__() |         super(SessionSinglePool, self).__init__() | ||||||
| 
 | 
 | ||||||
|         # reuse the same adapters |         # reuse the same adapters | ||||||
|         self.adapters.clear() |         with RLock(): | ||||||
|         self.mount('https://', next(https_adapters)) |             self.adapters.clear() | ||||||
|         self.mount('http://', next(http_adapters)) |             self.mount('https://', next(https_adapters)) | ||||||
|  |             self.mount('http://', next(http_adapters)) | ||||||
| 
 | 
 | ||||||
|     def close(self): |     def close(self): | ||||||
|         """Call super, but clear adapters since there are managed globaly""" |         """Call super, but clear adapters since there are managed globaly""" | ||||||
| @ -67,7 +70,6 @@ class SessionSinglePool(requests.Session): | |||||||
| 
 | 
 | ||||||
| def request(method, url, **kwargs): | def request(method, url, **kwargs): | ||||||
|     """same as requests/requests/api.py request(...) except it use SessionSinglePool and force proxies""" |     """same as requests/requests/api.py request(...) except it use SessionSinglePool and force proxies""" | ||||||
|     global settings |  | ||||||
|     session = SessionSinglePool() |     session = SessionSinglePool() | ||||||
|     kwargs['proxies'] = settings['outgoing'].get('proxies', None) |     kwargs['proxies'] = settings['outgoing'].get('proxies', None) | ||||||
|     response = session.request(method=method, url=url, **kwargs) |     response = session.request(method=method, url=url, **kwargs) | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Adam Tauber
						Adam Tauber