Created
June 23, 2025 20:33
-
-
Save PratikDeoghare/61d49d8fbbdc31589f0e86506e0ffe40 to your computer and use it in GitHub Desktop.
whatif
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 code, os, sys | |
| prompt = '> ' | |
| def read_fork(): | |
| global prompt | |
| while True: | |
| s = input(prompt) | |
| s = s.strip() | |
| if s == 'fork' or s == 'whatif': | |
| prompt = '>' + prompt | |
| if os.fork() == 0: | |
| pass | |
| else: | |
| os.wait() | |
| prompt = prompt[1:] | |
| elif s == 'unfork' or s == 'done': | |
| sys.exit() | |
| else: | |
| return s | |
| console = code.InteractiveConsole() | |
| while True: | |
| src = read_fork() | |
| console.runsource(src) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment