Repository URL to install this package:
|
Version:
0.32.0 ▾
|
# Copyright (c) 2015 Docker, Inc. All rights reserved.
"""
Helpers to set up signals to show stack traces (default SIGQUIT) and analyze heap
(default SIGUSR1).
For example, run this in your main thread. (You can only set up signal handlers
in the main thread.)::
import appstatus.signals
appstatus.signals.setup_signals()
"""
import json
import signal
import sys
from . import utils
def setup_signals(stacks=signal.SIGQUIT, heap=signal.SIGUSR1):
"""Help set up signal handlers for:
Args:
stacks (signum): Signal to trigger printing all thread stacks on
stderr. Default to SIGQUIT.
heap (signum): Signal to trigger heap analysize (heapy) and print
result on stderr. Default to SIGUSR1.
"""
signal.signal(stacks, _sighandler_stacks)
signal.signal(heap, _sighandler_heap)
def _sighandler_stacks(sig, frame):
res = utils.dump_stacks()
print >>sys.stderr, json.dumps(res, indent=2)
def _sighandler_heap(sig, frame):
res = utils.analyze_heap()
print >>sys.stderr, json.dumps(res, indent=2)