Print thread stack traces on SIGUSR1

This commit is contained in:
Bastian Kleineidam 2013-01-22 18:16:53 +01:00
parent 9b8cb67d78
commit 7134c0bb05
2 changed files with 20 additions and 0 deletions

View file

@ -2,6 +2,8 @@
Features:
- checking: Support <link rel="dns-prefetch"> URLs.
- logging: Sending SIGUSR1 signal prints the stack trace of all current
running threads. This makes it easier to debug deadlocks.
Fixes:
- checking: Fix a crash when closing a Word document after scanning failed.

View file

@ -32,6 +32,8 @@ if _dnspath not in sys.path:
sys.path.insert(0, _dnspath)
del _dnspath
import re
import signal
import traceback
from . import i18n
import _LinkChecker_configdata as configdata
@ -176,3 +178,19 @@ def find_third_party_modules ():
sys.path.append(os.path.join(third_party, "dnspython"))
find_third_party_modules()
# install SIGUSR1 handler
from .decorators import signal_handler
@signal_handler(signal.SIGUSR1)
def print_threadstacks(sig, frame):
"""Print stack traces of all running threads."""
log.warn(LOG_THREAD, "*** STACKTRACE START ***")
for threadId, stack in sys._current_frames().items():
log.warn(LOG_THREAD, "# ThreadID: %s" % threadId)
for filename, lineno, name, line in traceback.extract_stack(stack):
log.warn(LOG_THREAD, 'File: "%s", line %d, in %s' % (filename, lineno, name))
line = line.strip()
if line:
log.warn(LOG_THREAD, " %s" % line)
log.warn(LOG_THREAD, "*** STACKTRACE END ***")