|  | 
 |  | 
 | 
												
													
														| 19 |  import threading
 | 19 |  import threading
 | 
												
													
														| 20 |  from thread import start_new_thread
 | 20 |  from thread import start_new_thread
 | 
												
													
														| 21 |  from time import time
 | 21 |  from time import time
 | 
												
													
														|  | 
 | 22 | +from uuid import uuid4
 | 
												
													
														| 22 |  import searx.poolrequests as requests_lib
 | 23 |  import searx.poolrequests as requests_lib
 | 
												
													
														| 23 |  from searx.engines import (
 | 24 |  from searx.engines import (
 | 
												
													
														| 24 |      categories, engines
 | 25 |      categories, engines
 | 
												
											
												
													
														|  | 
 |  | 
 | 
												
													
														| 56 |  def threaded_requests(requests):
 | 57 |  def threaded_requests(requests):
 | 
												
													
														| 57 |      timeout_limit = max(r[2]['timeout'] for r in requests)
 | 58 |      timeout_limit = max(r[2]['timeout'] for r in requests)
 | 
												
													
														| 58 |      search_start = time()
 | 59 |      search_start = time()
 | 
												
													
														|  | 
 | 60 | +    search_id = uuid4().__str__()
 | 
												
													
														| 59 |      for fn, url, request_args, engine_name in requests:
 | 61 |      for fn, url, request_args, engine_name in requests:
 | 
												
													
														| 60 |          request_args['timeout'] = timeout_limit
 | 62 |          request_args['timeout'] = timeout_limit
 | 
												
													
														| 61 |          th = threading.Thread(
 | 63 |          th = threading.Thread(
 | 
												
													
														| 62 |              target=search_request_wrapper,
 | 64 |              target=search_request_wrapper,
 | 
												
													
														| 63 |              args=(fn, url, engine_name),
 | 65 |              args=(fn, url, engine_name),
 | 
												
													
														| 64 |              kwargs=request_args,
 | 66 |              kwargs=request_args,
 | 
												
													
														| 65 | -            name='search_request',
 |  | 
 | 
												
													
														|  | 
 | 67 | +            name=search_id,
 | 
												
													
														| 66 |          )
 | 68 |          )
 | 
												
													
														| 67 |          th._engine_name = engine_name
 | 69 |          th._engine_name = engine_name
 | 
												
													
														| 68 |          th.start()
 | 70 |          th.start()
 | 
												
													
														| 69 |  
 | 71 |  
 | 
												
													
														| 70 |      for th in threading.enumerate():
 | 72 |      for th in threading.enumerate():
 | 
												
													
														| 71 | -        if th.name == 'search_request':
 |  | 
 | 
												
													
														|  | 
 | 73 | +        if th.name == search_id:
 | 
												
													
														| 72 |              remaining_time = max(0.0, timeout_limit - (time() - search_start))
 | 74 |              remaining_time = max(0.0, timeout_limit - (time() - search_start))
 | 
												
													
														| 73 |              th.join(remaining_time)
 | 75 |              th.join(remaining_time)
 | 
												
													
														| 74 |              if th.isAlive():
 | 76 |              if th.isAlive():
 |