Mercurial > public > mercurial-scm > hg
comparison contrib/showstack.py @ 40036:acf5dbe39478
showstack: also handle SIGALRM
This is looking *very* handy when debugging mysterious hangs in a
test: you can wrap a hanging invocation in
`perl -e 'alarm shift @ARGV; exec @ARGV' 1`
for example, a hanging `hg pull` becomes
`perl -e 'alarm shift @ARGV; exec @ARGV' 1 hg pull`
where the `1` is the timeout in seconds before the process will be hit
with SIGALRM. After making that edit to the test file, you can then
use --extra-config-opt on run-tests.py to globaly enable showstack
during the test run, so you'll get full stack traces as you force your
hg to exit.
I wonder (but only a little, not enough to take action just yet) if we
should wire up some scaffolding in run-tests itself to automatically
wrap all commands in alarm(3) somehow to avoid hangs in the future?
Differential Revision: https://phab.mercurial-scm.org/D4870
author | Augie Fackler <augie@google.com> |
---|---|
date | Wed, 03 Oct 2018 16:03:16 -0400 |
parents | c9eb92fb87b7 |
children | 6dae1f31c6c9 |
comparison
equal
deleted
inserted
replaced
40035:7a347d362a45 | 40036:acf5dbe39478 |
---|---|
2 # | 2 # |
3 # binds to both SIGQUIT (Ctrl-\) and SIGINFO (Ctrl-T on BSDs) | 3 # binds to both SIGQUIT (Ctrl-\) and SIGINFO (Ctrl-T on BSDs) |
4 """dump stack trace when receiving SIGQUIT (Ctrl-\) and SIGINFO (Ctrl-T on BSDs) | 4 """dump stack trace when receiving SIGQUIT (Ctrl-\) and SIGINFO (Ctrl-T on BSDs) |
5 """ | 5 """ |
6 | 6 |
7 from __future__ import absolute_import | 7 from __future__ import absolute_import, print_function |
8 import signal | 8 import signal |
9 import sys | 9 import sys |
10 import traceback | 10 import traceback |
11 | 11 |
12 def sigshow(*args): | 12 def sigshow(*args): |
13 sys.stderr.write("\n") | 13 sys.stderr.write("\n") |
14 traceback.print_stack(args[1], limit=10, file=sys.stderr) | 14 traceback.print_stack(args[1], limit=10, file=sys.stderr) |
15 sys.stderr.write("----\n") | 15 sys.stderr.write("----\n") |
16 | 16 |
17 def sigexit(*args): | |
18 sigshow(*args) | |
19 print('alarm!') | |
20 sys.exit(1) | |
21 | |
17 def extsetup(ui): | 22 def extsetup(ui): |
18 signal.signal(signal.SIGQUIT, sigshow) | 23 signal.signal(signal.SIGQUIT, sigshow) |
24 signal.signal(signal.SIGALRM, sigexit) | |
19 try: | 25 try: |
20 signal.signal(signal.SIGINFO, sigshow) | 26 signal.signal(signal.SIGINFO, sigshow) |
21 except AttributeError: | 27 except AttributeError: |
22 pass | 28 pass |