[tor-commits] [sbws/master] chg: scanner: !refactor waiting for results

juga at torproject.org juga at torproject.org
Thu Mar 21 18:30:42 UTC 2019


commit c89bf57ff955d5ba2e5b994d5a38357843eea1e1
Author: juga0 <juga at riseup.net>
Date:   Mon Mar 4 18:46:23 2019 +0000

    chg: scanner: !refactor waiting for results
    
    Move to a function waiting for results at the end of the loop.
---
 sbws/core/scanner.py | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/sbws/core/scanner.py b/sbws/core/scanner.py
index 4ad2cb5..484a440 100644
--- a/sbws/core/scanner.py
+++ b/sbws/core/scanner.py
@@ -483,16 +483,8 @@ def main_loop(args, conf, controller, relay_list, circuit_builder, result_dump,
                 # sleep is non-blocking since happens in the main process.
                 time.sleep(time_to_sleep)
                 pending_results = [r for r in pending_results if not r.ready()]
-        time_waiting = 0
-        while (len(pending_results) > 0
-               and time_waiting <= TIMEOUT_MEASUREMENTS):
-            log.debug("Number of pending measurement threads %s after "
-                      "a prioritization loop.", len(pending_results))
-            time.sleep(time_to_sleep)
-            time_waiting += time_to_sleep
-            pending_results = [r for r in pending_results if not r.ready()]
-        if time_waiting > TIMEOUT_MEASUREMENTS:
-            dumpstacks()
+
+        wait_for_results(time_to_sleep, pending_results)
         loop_tstop = time.time()
         loop_tdelta = (loop_tstop - loop_tstart) / 60
         log.debug("Measured %s relays in %s minutes", num_relays, loop_tdelta)
@@ -503,6 +495,19 @@ def main_loop(args, conf, controller, relay_list, circuit_builder, result_dump,
             stop_threads(signal.SIGTERM, None)
 
 
+def wait_for_results(time_to_sleep, pending_results):
+    time_waiting = 0
+    while (len(pending_results) > 0
+           and time_waiting <= TIMEOUT_MEASUREMENTS):
+        log.debug("Number of pending measurement threads %s after "
+                  "a prioritization loop.", len(pending_results))
+        time.sleep(time_to_sleep)
+        time_waiting += time_to_sleep
+        pending_results = [r for r in pending_results if not r.ready()]
+    if time_waiting > TIMEOUT_MEASUREMENTS:
+        dumpstacks()
+
+
 def run_speedtest(args, conf):
     """Initializes all the data and threads needed to measure the relays.
 





More information about the tor-commits mailing list