restart interactive interpreter?
How does one restart the Python interpreter in the interactive panel?
I tried sys.exit(), which I thought would make a new one start once the current one had exited. However, it just printed "EXIT (0)" and continued running.
ccc last edited by
Shutting down Pythonista:<br>
Keeping your Pythonista script from going to sleep:<br>
Thanks for the suggestion. It may help, but it's still rather hack-ish. I wish @omz would change Pythonista to let the Python interpreter exit as it normally would, either from a crash, a call for sys.exit(), or other appropriate method call. Then Pythonista could either start a new interpreter automatically or prompt the user to tap a button to start one.
So, just to follow-up...
Through some experimentation with
os.getpid(), I learned that the interactive interpreter and all of my programs are running from the same process. I was surprised by this because I expected a new interpreter to start each time a program is run and it would terminate when the program does. Apparently, the way @omz implemented Pythonista, the Python interpreter isn't a subprocess, it's part of the main one and it's reset whenever a program is run. That same interpreter (or a parallel one?) handles the interactive prompt, but there's no way to reset it.
It also appears that
sys.exit()is trapped to print that
EXIT (0)message. IMHO, I think the trap should reset the interpreter, if not start a new one.
omz last edited by
@lsloan I'd love to run the interpreter in a sub-process, but that's not possible on iOS (Apple's policy).
I understand, @omz. You need to play by their rules.
Could you describe what Pythonista does whenever a program is run? It seems to clear the environment first, because variables don't retain their values from one run to the next. If calls to
sys.exit()are trapped, could it also clear the environment then?