[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [stem/master] When running tests, install signal handlers that log stack traces
commit cb774063b50e0909b9c34645d12bd6a89bcdd9df
Author: teor <teor@xxxxxxxxxxxxxx>
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',
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits