Skip to content

Instantly share code, notes, and snippets.

@PratikDeoghare
Created June 23, 2025 20:33
Show Gist options
  • Select an option

  • Save PratikDeoghare/61d49d8fbbdc31589f0e86506e0ffe40 to your computer and use it in GitHub Desktop.

Select an option

Save PratikDeoghare/61d49d8fbbdc31589f0e86506e0ffe40 to your computer and use it in GitHub Desktop.
whatif
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