Created
October 5, 2025 00:56
-
-
Save jumbosushi/bd9bd0b440536acca7469235de94f56a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import signal | |
| import sys | |
| import pty | |
| def main(is_child): | |
| # Set up signal handler | |
| def sigint_handler(signum, frame): | |
| role = "CHILD" if is_child else "PARENT" | |
| print(f"\n[{role}] Caught SIGINT, exiting...") | |
| sys.exit(0) | |
| signal.signal(signal.SIGINT, sigint_handler) | |
| if is_child: | |
| print("[CHILD] Running in PTY, press Ctrl+C...") | |
| else: | |
| print("[PARENT] Spawning child in PTY...") | |
| pty.spawn([sys.executable, __file__, "child"]) | |
| print("[PARENT] pty.spawn() returned, press Ctrl+C...") | |
| signal.pause() | |
| if __name__ == "__main__": | |
| is_child = len(sys.argv) > 1 and sys.argv[1] == "child" | |
| main(is_child) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment