
On 30 October 2017 at 15:53, Antoine Pitrou <solipsis@pitrou.net> wrote:
On Tue, 31 Oct 2017 01:44:10 +1000 Nick Coghlan <ncoghlan@gmail.com> wrote:
A few specific notes here:
1. As you say, this sort of already works in notebooks, since instructors can say to run "!pip install requests" and then restart the language kernel. 2. We could probably replicate that style in IDLE, since that runs user code in a subprocess, similar to the way Jupyter language kernels are separate from the frontend client 3. We can't replicate it as readily in the regular REPL, since that runs Python code directly in the current process, but even there I believe we could potentially trigger a full process restart via execve (or the C++ style _execve on Windows)
(We'd want a real process restart, rather than emulating it by calling Py_Initialize & Py_Finalize multiple times, as not every module properly supports multiple initialise/finalise cycles within a single process, and module-specific quirks are exactly what we'd be trying to avoid by forcing an interpreter restart)
The main difference, though, is that a notebook will reload and replay all your session, while restarting the regular REPL will simply lose all current work. I think that makes the idea much less appealing.
Also, on Windows, I believe that any emulation of execve either leaves the original process in memory, or has problems getting console inheritance right. It's been a long time since I worked at that level, and things may be better now, but getting a robust "restart this process" interface in Windows would need some care (that's one of the reasons the py launcher runs Python as a subprocess rather than doing any sort of exec equivalent). Paul