Skip to content

Instantly share code, notes, and snippets.

@jumbosushi
Created October 5, 2025 00:56
Show Gist options
  • Select an option

  • Save jumbosushi/bd9bd0b440536acca7469235de94f56a to your computer and use it in GitHub Desktop.

Select an option

Save jumbosushi/bd9bd0b440536acca7469235de94f56a to your computer and use it in GitHub Desktop.
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