Sfoglia il codice sorgente

[fix] thread safe threaded_requests() function

Adam Tauber 8 anni fa
parent
commit
55abf07a4f
1 ha cambiato i file con 4 aggiunte e 2 eliminazioni
  1. 4
    2
      searx/search.py

+ 4
- 2
searx/search.py Vedi File

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