[tor-commits] [sbws/master] scanner: stop threads when there're not destinations

juga at torproject.org juga at torproject.org
Wed Feb 27 09:11:30 UTC 2019


commit 3fe64b06253f9342e627c5d4b9db065cd03a8a7e
Author: juga0 <juga at riseup.net>
Date:   Tue Feb 26 10:48:38 2019 +0000

    scanner: stop threads when there're not destinations
    
    Exit the scanner with error stoping threads first when there is not
    any functional destination, since the destinations can not be recovered.
    After merging #28897, `stop_threads` can be used (instroduced in #28869).
---
 sbws/core/scanner.py | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/sbws/core/scanner.py b/sbws/core/scanner.py
index 4e981fd..00071be 100644
--- a/sbws/core/scanner.py
+++ b/sbws/core/scanner.py
@@ -37,7 +37,7 @@ rd = None
 controller = None
 
 
-def stop_threads(signal, frame):
+def stop_threads(signal, frame, exit_code=0):
     global rd, pool
     log.debug('Stopping sbws.')
     # Avoid new threads to start.
@@ -49,7 +49,7 @@ def stop_threads(signal, frame):
     rd.thread.join()
     # Stop Tor thread
     controller.close()
-    sys.exit(0)
+    sys.exit(exit_code)
 
 
 signal.signal(signal.SIGTERM, stop_threads)
@@ -247,11 +247,12 @@ def measure_relay(args, conf, destinations, cb, rl, relay):
     # If there is no any destination at this point, it can not continue.
     if not dest:
         # XXX: this should return a ResultError
+        # instead of stopping the scanner once a destination can be recovered.
         log.critical("There are not any functional destinations.\n"
                      "It is recommended to set several destinations so that "
                      "the scanner can continue if one fails.")
-        # This should raise an error so that the caller can close the pool.
-        exit(1)
+        # Exit the scanner with error stopping threads first.
+        stop_threads(signal.SIGTERM, None, 1)
     # Pick a relay to help us measure the given relay. If the given relay is an
     # exit, then pick a non-exit. Otherwise pick an exit.
     helper = None





More information about the tor-commits mailing list