on master help sign in
[mod] better search request exception handling
commit1c969186bfdabbc5d6c804fa5f1f2fc068492b5f authorAdam Tauber <asciimoo@gmail.com> dateFri 19 Dec 2014, 20:01 (12 years ago) parent8c05c00
1 file changed+16−12
searx/search.py+16−12
searx/search.py+16−12
@@ -34,14 +34,27 @@ from searx.query import Query
3434number_of_searches = 0
3535
3636
37+def search_request_wrapper(fn, url, engine_name, **kwargs):
38+ try:
39+ return fn(url, **kwargs)
40+ except Exception, e:
41+ # increase errors stats
42+ engines[engine_name].stats['errors'] += 1
43+
44+ # print engine name and specific error message
45+ print('[E] Error with engine "{0}":\n\t{1}'.format(
46+ engine_name, str(e)))
47+ return
48+
49+
3750def threaded_requests(requests):
3851 timeout_limit = max(r[2]['timeout'] for r in requests)
3952 search_start = time()
4053 for fn, url, request_args, engine_name in requests:
4154 request_args['timeout'] = timeout_limit
4255 th = threading.Thread(
43− target=fn,
44− args=(url,),
56+ target=search_request_wrapper,
57+ args=(fn, url, engine_name),
4558 kwargs=request_args,
4659 name='search_request',
4760 )
@@ -79,16 +92,7 @@ def make_callback(engine_name, results_queue, callback, params):
7992 return
8093
8194 # callback
82− try:
83− search_results = callback(response)
84− except Exception, e:
85− # increase errors stats
86− engines[engine_name].stats['errors'] += 1
87−
88− # print engine name and specific error message
89− print '[E] Error with engine "{0}":\n\t{1}'.format(
90− engine_name, str(e))
91− return
95+ search_results = callback(response)
9296
9397 # add results
9498 for result in search_results: