Skip to content

Commit 6e5eeb4

Browse files
committed
Dump thread stacks on SIGUSR1 when running tests to troubleshoot
deadlocks and similar.
1 parent 02576d1 commit 6e5eeb4

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

tests/conftest.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
import re
99
import secrets
1010
import shutil
11+
import signal
1112
import socket
1213
import subprocess
1314
import sys
1415
import threading
1516
import time
17+
import traceback
1618
from functools import partial
1719
from pathlib import Path
1820
from typing import Dict, List, Optional
@@ -76,6 +78,22 @@ def pytest_addoption(parser):
7678
'is uploaded to the test aggregation server. ')
7779

7880

81+
def debug(sig, frame):
82+
with open('/tmp/python-dump.txt', 'w') as f:
83+
f.write('Test')
84+
try:
85+
for thr in threading.enumerate():
86+
f.write(str(thr))
87+
f.write('\n')
88+
traceback.print_stack(sys._current_frames()[thr.ident], file=f)
89+
f.write('\n\n')
90+
except Exception as ex:
91+
f.write(str(ex))
92+
93+
94+
signal.signal(signal.SIGUSR1, debug) # Register handler
95+
96+
7997
def _get_executors(config: Dict[str, str]) -> List[str]:
8098
execs_str = config.getoption('executors')
8199
execs = execs_str.split(',')

0 commit comments

Comments
 (0)