[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [sbws/master] scanner: add function to stop threads on SIGTERM
commit b85fb114278d81d74b0768ab1ba9f88cd1e929d4
Author: juga0 <juga@xxxxxxxxxx>
Date: Tue Jan 8 15:57:46 2019 +0000
scanner: add function to stop threads on SIGTERM
---
sbws/core/scanner.py | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/sbws/core/scanner.py b/sbws/core/scanner.py
index b926149..7c2a937 100644
--- a/sbws/core/scanner.py
+++ b/sbws/core/scanner.py
@@ -1,5 +1,8 @@
''' Measure the relays. '''
+import signal
+import sys
+
from ..lib.circuitbuilder import GapsCircuitBuilder as CB
from ..lib.resultdump import ResultDump
from ..lib.resultdump import ResultSuccess, ResultErrorCircuit
@@ -31,6 +34,24 @@ rd = None
controller = None
+def stop_threads(signal, frame):
+ global rd, pool
+ log.debug('Stopping sbws.')
+ # Avoid new threads to start.
+ settings.set_end_event()
+ # Stop Pool threads
+ pool.close()
+ pool.join()
+ # Stop ResultDump thread
+ rd.thread.join()
+ # Stop Tor thread
+ controller.close()
+ sys.exit(0)
+
+
+signal.signal(signal.SIGTERM, stop_threads)
+
+
def timed_recv_from_server(session, dest, byte_range):
''' Request the **byte_range** from the URL at **dest**. If successful,
return True and the time it took to download. Otherwise return False and an
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits