Skip to content

Instantly share code, notes, and snippets.

@jumbosushi
Created October 2, 2025 03:38
Show Gist options
  • Select an option

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

Select an option

Save jumbosushi/5deccfa9e156e53e1e33b87c65c9429b to your computer and use it in GitHub Desktop.
import signal
import sys
import time
import pty
from functools import partial
def signal_handler(tag, signum, frame):
print(f"\n{tag} Received SIGINT, exiting...")
exit(0)
def get_tag(depth):
return f"{' ' * (depth * 4)} [{ 'parent' if depth == 0 else 'child' }]"
def main(depth):
tag = get_tag(depth)
signal.signal(signal.SIGINT, partial(signal_handler, tag))
print(f"{tag} Waiting for SIGINT ...")
if depth < 1:
print(f"{tag} ================")
print(f"{tag} Calling pty.spawn() ...")
pty.spawn([sys.executable, __file__, str(depth + 1), "pty"])
print(f"{tag} Returned")
while True:
time.sleep(1)
if __name__ == "__main__":
depth = int(sys.argv[1])
main(depth)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment