SearXNG is a free internet metasearch engine which aggregates results from various search services and databases. Users are neither tracked nor profiled.
Python bingbravedegoogleduckduckgogooglemetasearchprivacypythonqwantsearchsearch-enginesearxsearxngstartpageyahoo
[fix] proper search timeout handling
Adam Taubera5324d9d820f
diff --git a/searx/search.py b/searx/search.pyindex 5b5cc6200..fafa8a63a 100644--- a/searx/search.py+++ b/searx/search.py@@ -21,6 +21,8 @@ import refrom itertools import izip_longest, chainfrom datetime import datetimefrom operator import itemgetter+from Queue import Queue+from time import timefrom urlparse import urlparse, unquotefrom searx.engines import (categories, engines@@ -34,6 +36,8 @@ number_of_searches = 0def threaded_requests(requests):+ timeout_limit = max(r[2]['timeout'] for r in requests)+ search_start = time()for fn, url, request_args in requests:th = threading.Thread(target=fn,@@ -45,7 +49,11 @@ def threaded_requests(requests):for th in threading.enumerate():if th.name == 'search_request':- th.join()+ remaining_time = max(0.0, timeout_limit - (time() - search_start))+ th.join(remaining_time)+ if th.isAlive():+ print('engine timeout')+# get default reqest parameter@@ -56,7 +64,7 @@ def default_request_params():# create a callback wrapper for the search engine resultsdef make_callback(engine_name,- results,+ results_queue,suggestions,answers,infoboxes,@@ -74,7 +82,7 @@ def make_callback(engine_name,except Exception, e:# increase errors statsengines[engine_name].stats['errors'] += 1- results[engine_name] = cb_res+ results_queue.put_nowait((engine_name, cb_res))# print engine name and specific error messageprint '[E] Error with engine "{0}":\n\t{1}'.format(@@ -104,7 +112,7 @@ def make_callback(engine_name,# append resultcb_res.append(result)- results[engine_name] = cb_res+ results_queue.put_nowait((engine_name, cb_res))# update stats with current page-load-timeengines[engine_name].stats['page_load_time'] += \@@ -420,7 +428,7 @@ class Search(object):# init varsrequests = []- results = {}+ results_queue = Queue()suggestions = set()answers = set()infoboxes = []@@ -468,7 +476,7 @@ class Search(object):# create a callback wrapper for the search engine resultscallback = make_callback(selected_engine['name'],- results,+ results_queue,suggestions,answers,infoboxes,@@ -502,6 +510,11 @@ class Search(object):# send all search-requestthreaded_requests(requests)+ results = {}+ while not results_queue.empty():+ engine_name, engine_results = results_queue.get_nowait()+ results[engine_name] = engine_results+# update engine-specific statsfor engine_name, engine_results in results.items():engines[engine_name].stats['search_count'] += 1