[fix] lock request pool generator

This commit is contained in:
Adam Tauber 2015-10-31 14:40:59 +01:00
parent 5d49c15f79
commit 357fc47811
1 changed files with 6 additions and 4 deletions

View File

@ -1,5 +1,7 @@
import requests
from itertools import cycle
from threading import RLock
from searx import settings
@ -55,6 +57,7 @@ class SessionSinglePool(requests.Session):
super(SessionSinglePool, self).__init__()
# reuse the same adapters
with RLock():
self.adapters.clear()
self.mount('https://', next(https_adapters))
self.mount('http://', next(http_adapters))
@ -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)