Stop Hook Exit Hang - Troubleshooting¶
Problem: amplihack hangs for 10-13 seconds on exit, blocking sys.stdin.read() during cleanup.
Status: ✅ Fixed in v0.9.1
Quick Fix (If Running Old Version)¶
# Upgrade to v0.9.1 or later
pip install --upgrade amplihack
# Or force kill if already hung
Ctrl+C (may need to press multiple times)
pkill -9 amplihack
Symptoms¶
Before Fix (v0.9.0 and earlier):
- Exit takes 10-13 seconds instead of <3 seconds
- No visible output during hang
- Process appears frozen
- Pressing Ctrl+C eventually works but feels unresponsive
After Fix (v0.9.1+):
- Exit completes in <3 seconds
- Clean shutdown behavior
- No hanging or blocking
Root Cause¶
The stop hook (power_steering.stop) was calling read_input() during atexit cleanup, which blocked on sys.stdin.read(). During shutdown:
- Python's
atexithandlers run - Stop hook calls
read_input() read_input()blocks onsys.stdin.read()- stdin is closed/detached during shutdown
- Read operation hangs until timeout (10-13 seconds)
The Fix¶
Added centralized shutdown detection that:
- Checks
AMPLIHACK_SHUTDOWN_IN_PROGRESSenvironment variable - Skips stdin reads during shutdown
- Returns safe defaults immediately
- Completes cleanup in <3 seconds
See Shutdown Detection Explanation for technical details.
Verifying the Fix¶
# Check your version
amplihack --version
# Should be v0.9.1 or later for the fix
# Test exit behavior
amplihack
# ... do some work ...
# Type 'exit' or Ctrl+D
# Should exit cleanly in <3 seconds
If Still Experiencing Issues¶
Issue: Hangs persist after upgrade¶
Check:
# Verify you're running the new version
python -c "import amplihack; print(amplihack.__version__)"
# Should show 0.9.1 or later
Solution: Clear any cached installations
Issue: Environment variable not being set¶
Check:
# During normal operation, this should be unset
echo $AMPLIHACK_SHUTDOWN_IN_PROGRESS
# (should be empty)
# If it's set to "1", that's blocking normal operations
unset AMPLIHACK_SHUTDOWN_IN_PROGRESS
Issue: Custom hooks experiencing similar hangs¶
If you've written custom hooks that read stdin, see How to Add Shutdown Detection to Custom Hooks.
Related Issues¶
- GitHub Issue #1896: Stop hook exit hang
- Power Steering Troubleshooting
Need More Help?¶
- Check Shutdown Detection Reference for API details
- Review DISCOVERIES.md for known issues
- Report a bug if the issue persists