Created
October 2, 2025 03:38
-
-
Save jumbosushi/5deccfa9e156e53e1e33b87c65c9429b 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 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