Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When running tests, install signal handlers that log stack traces #11

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions test/__init__.py
Expand Up @@ -16,10 +16,28 @@
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',
Expand Down