Commit c89bf57f authored by juga's avatar juga
Browse files

chg: scanner: !refactor waiting for results

Move to a function waiting for results at the end of the loop.
parent 901cf921
Loading
Loading
Loading
Loading
+15 −10
Original line number Diff line number Diff line
@@ -483,6 +483,19 @@ 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()]

        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)
        # In a testing network, exit after first loop
        if controller.get_conf('TestingTorNetwork') == '1':
            log.info("In a testing network, exiting after the first loop.")
            # Threads should be closed nicely in some refactor
            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):
@@ -493,14 +506,6 @@ def main_loop(args, conf, controller, relay_list, circuit_builder, result_dump,
        pending_results = [r for r in pending_results if not r.ready()]
    if time_waiting > TIMEOUT_MEASUREMENTS:
        dumpstacks()
        loop_tstop = time.time()
        loop_tdelta = (loop_tstop - loop_tstart) / 60
        log.debug("Measured %s relays in %s minutes", num_relays, loop_tdelta)
        # In a testing network, exit after first loop
        if controller.get_conf('TestingTorNetwork') == '1':
            log.info("In a testing network, exiting after the first loop.")
            # Threads should be closed nicely in some refactor
            stop_threads(signal.SIGTERM, None)


def run_speedtest(args, conf):