Repository navigation
Fix signal handler re-entrancy and hang on Ctrl+C - #14852
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the Python unit-test signal handling utilities to avoid re-entrant cleanup and to prevent hangs on Ctrl+C/SIGTERM by forcing a hard process exit once cleanup begins.
Changes:
- Add a module-level
_cleanup_in_progressguard to prevent re-entrant signal handling and force-exit on a second signal during cleanup. - Replace
sys.exit(1)withos._exit(1)to avoid hangs caused by threads blocking normal interpreter shutdown.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| from rspy import log | ||
| import sys, signal | ||
| import os, sys, signal |
There was a problem hiding this comment.
sys is no longer used in this module after switching from sys.exit to os._exit. Please remove the unused import (or, if you keep os._exit, use sys to flush stdio before exiting).
| log.w("got signal", signum, "aborting... ") | ||
| signal_handler() | ||
| sys.exit(1) | ||
| os._exit(1) |
There was a problem hiding this comment.
os._exit() bypasses Python exception propagation and stdio flushing. If signal_handler() raises or logs buffered output, the process may continue unexpectedly or drop the last log lines. Consider wrapping signal_handler() in a try/finally (or try/except + finally) that always flushes output and then calls os._exit(1) so abort is guaranteed even if cleanup fails.
Summary
_cleanup_in_progressguard ensures a second Ctrl+C (or SIGTERM) during cleanup force-exits immediately viaos._exit(1)instead of recursing into_cleanup_devicesagainos._exit(1)instead ofsys.exit(1)after cleanup to avoid hanging on BrainStem USB hub threads that blockSystemExitTest plan
🤖 Generated with Claude Code