Handle SIGTERM/SIGINT - refuse shutdown during installation.
(signum: int, frame: object)
| 735 | |
| 736 | |
| 737 | def signal_handler(signum: int, frame: object) -> None: |
| 738 | """Handle SIGTERM/SIGINT - refuse shutdown during installation.""" |
| 739 | global _installation_in_progress |
| 740 | |
| 741 | signal_name = "SIGTERM" if signum == signal.SIGTERM else "SIGINT" |
| 742 | |
| 743 | with _installation_lock: |
| 744 | if _installation_in_progress: |
| 745 | logging.warning( |
| 746 | f"Received {signal_name} during active package installation. " |
| 747 | f"Refusing graceful shutdown. Use force kill (SIGKILL) to terminate." |
| 748 | ) |
| 749 | print( |
| 750 | f"\n⚠️ {signal_name} received during package installation\n" |
| 751 | f"⚠️ Cannot shutdown gracefully while installation is active\n" |
| 752 | f"⚠️ Installation must complete atomically to prevent corruption\n" |
| 753 | f"⚠️ Use 'kill -9 {os.getpid()}' to force termination (may corrupt packages)\n", |
| 754 | flush=True, |
| 755 | ) |
| 756 | return # Refuse shutdown |
| 757 | else: |
| 758 | logging.info(f"Received {signal_name}, shutting down gracefully") |
| 759 | cleanup_and_exit() |
| 760 | |
| 761 | |
| 762 | def cleanup_and_exit() -> None: |
nothing calls this directly
no test coverage detected