| 
				
			 | 
			
			
				@@ -34,14 +34,27 @@ from searx.query import Query 
			 | 
		
	
		
			
			| 
				34
			 | 
			
				34
			 | 
			
			
				 number_of_searches = 0 
			 | 
		
	
		
			
			| 
				35
			 | 
			
				35
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				36
			 | 
			
				36
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				
			 | 
			
				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
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				37
			 | 
			
				50
			 | 
			
			
				 def threaded_requests(requests): 
			 | 
		
	
		
			
			| 
				38
			 | 
			
				51
			 | 
			
			
				     timeout_limit = max(r[2]['timeout'] for r in requests) 
			 | 
		
	
		
			
			| 
				39
			 | 
			
				52
			 | 
			
			
				     search_start = time() 
			 | 
		
	
		
			
			| 
				40
			 | 
			
				53
			 | 
			
			
				     for fn, url, request_args, engine_name in requests: 
			 | 
		
	
		
			
			| 
				41
			 | 
			
				54
			 | 
			
			
				         request_args['timeout'] = timeout_limit 
			 | 
		
	
		
			
			| 
				42
			 | 
			
				55
			 | 
			
			
				         th = threading.Thread( 
			 | 
		
	
		
			
			| 
				43
			 | 
			
				
			 | 
			
			
				-            target=fn, 
			 | 
		
	
		
			
			| 
				44
			 | 
			
				
			 | 
			
			
				-            args=(url,), 
			 | 
		
	
		
			
			| 
				
			 | 
			
				56
			 | 
			
			
				+            target=search_request_wrapper, 
			 | 
		
	
		
			
			| 
				
			 | 
			
				57
			 | 
			
			
				+            args=(fn, url, engine_name), 
			 | 
		
	
		
			
			| 
				45
			 | 
			
				58
			 | 
			
			
				             kwargs=request_args, 
			 | 
		
	
		
			
			| 
				46
			 | 
			
				59
			 | 
			
			
				             name='search_request', 
			 | 
		
	
		
			
			| 
				47
			 | 
			
				60
			 | 
			
			
				         ) 
			 | 
		
	
	
		
			
			| 
				
			 | 
			
			
				@@ -79,16 +92,7 @@ def make_callback(engine_name, results_queue, callback, params): 
			 | 
		
	
		
			
			| 
				79
			 | 
			
				92
			 | 
			
			
				             return 
			 | 
		
	
		
			
			| 
				80
			 | 
			
				93
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				81
			 | 
			
				94
			 | 
			
			
				         # 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) 
			 | 
		
	
		
			
			| 
				92
			 | 
			
				96
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				93
			 | 
			
				97
			 | 
			
			
				         # add results 
			 | 
		
	
		
			
			| 
				94
			 | 
			
				98
			 | 
			
			
				         for result in search_results: 
			 |