[tor-commits] [stem/master] When running tests, install signal handlers that log stack traces

atagar at torproject.org atagar at torproject.org
Wed Apr 10 18:22:31 UTC 2019


commit cb774063b50e0909b9c34645d12bd6a89bcdd9df
Author: teor <teor at torproject.org>
Date:   Wed Apr 10 20:25:02 2019 +1000

    When running tests, install signal handlers that log stack traces
    
    SIGUSR1: log stack trace and continue
    SIGABRT: log stack trace and exit(-1)
    
    Closes ticket 30012.
---
 test/__init__.py | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/test/__init__.py b/test/__init__.py
index fa9678af..dc1ab559 100644
--- a/test/__init__.py
+++ b/test/__init__.py
@@ -16,10 +16,28 @@ Unit and integration tests for the stem library. Helpers include...
 import collections
 import itertools
 import os
+import signal
+import sys
+import traceback
 
 import stem.util.enum
 import stem.version
 
+# Install signal handlers before doing anything else
+def log_traceback(sig, frame):
+  """Log a stack trace. exit(-1) if the signal was SIGABRT."""
+  message  = "Signal {} received.\nTraceback:\n".format(sig)
+  message += ''.join(traceback.format_stack(frame))
+  print(message)
+  if sig == signal.SIGABRT:
+    sys.exit(-1)
+
+# Register handlers
+# Log stack trace and exit
+signal.signal(signal.SIGABRT, log_traceback)
+# Log stack trace and continue
+signal.signal(signal.SIGUSR1, log_traceback)
+
 __all__ = [
   'network',
   'output',





More information about the tor-commits mailing list