You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Reload Python modules when running programs #50570
Every time IDLE is asked to run a program, it doesn't ensure that the
modules referenced by the program are completely loaded. This can cause
problems if one of those modules is also being edited, because once it
is loaded, any subsequent changes are not compiled and re-loaded.
PyUnit faced a similar problem and solved it with a custom importer
(http://pyunit.sourceforge.net/notes/reloading.html). Ideally, the
custom importer would be used in two places: The obvious choice is when
a program is run, unloading when it returns. The less obvious is when
the Python Shell window is opened, since import statements can be run
from there as well. Closing that window should cause all such imports
to be unloaded. Of course, care must be taken to insure that all run
commands are properly nested within the lifetime of a shell window.
When you run a program using F5 in IDLE,
it completely restarts the underlying interpreter!
If you meant a different way of running, please elaborate.
(Exception: it uses the same interpreter if you're running "idle -n"; this commonly happens on Windows if you rightclick->Edit with IDLE... a .py file - just don't use that.)
samwyse commented on Aug 15, 2010
samwysemannequin
MannequinAuthor
More actions
As it happens, I do use Windows and almost exclusively start IDLE via right-clicks on .py files. I've never seen the behavior you describe documented anywhere.
When you run a program using F5 in IDLE,
it completely restarts the underlying interpreter!
If you meant a different way of running, please elaborate.
(Exception: it uses the same interpreter if you're running "idle -n"; this commonly happens on Windows if you rightclick->Edit with IDLE... a .py file - just don't use that.)
As it happens, I do use Windows and almost exclusively start IDLE via right-clicks on .py files. I've never seen the behavior you describe documented anywhere.
You're right, it wasn't.
[IDLE does show a "==== No Subprocess ====" line in the IDLE shell when you launch it this way. Unfortunately, the significance of this (and of the absence of "====== Restart ======" lines on F5) wouldn't be obvious unless you followed IDLE development around 2.3... :-(]
If you're using Python up to 2.6/3.0, please fall back to starting IDLE from the Start menu → Programs → Python X.Y → IDLE, then use File→Open to open files.
Or upgrade to Python 2.7/3.1, where right click → Edit with IDLE was fixed [bpo-5847] to open IDLE in the fully-functional mode. Note however, that once you have an open IDLE, still want to use File→Open or you'll get *2* IDLEs running at once, each with its own shell.
In both cases you'll notice IDLE will *completely* restart the underlying Python each time you press F5. This eliminates any stale-module problems, but kills all variables and state you had; this might require a change of habits but in my experience it's well worth it.
[P.S. If you absolutely must have module reloading without killing the whole state, and you're willing to debug occasional issues, take a look at http://www.cherrypy.org/attachment/wiki/AutoReload/autoreload.py
and possibly http://www.codexon.com/posts/a-better-python-reload]
serwy commented on Dec 9, 2011
serwymannequin
Mannequin
More actions
Should this issue be closed? It is related to bpo-4691.
Activity
samwyse commentedon Jun 22, 2009
Every time IDLE is asked to run a program, it doesn't ensure that the
modules referenced by the program are completely loaded. This can cause
problems if one of those modules is also being edited, because once it
is loaded, any subsequent changes are not compiled and re-loaded.
PyUnit faced a similar problem and solved it with a custom importer
(http://pyunit.sourceforge.net/notes/reloading.html). Ideally, the
custom importer would be used in two places: The obvious choice is when
a program is run, unloading when it returns. The less obvious is when
the Python Shell window is opened, since import statements can be run
from there as well. Closing that window should cause all such imports
to be unloaded. Of course, care must be taken to insure that all run
commands are properly nested within the lifetime of a shell window.
cben commentedon Aug 15, 2010
When you run a program using F5 in IDLE,
it completely restarts the underlying interpreter!
If you meant a different way of running, please elaborate.
(Exception: it uses the same interpreter if you're running "idle -n"; this commonly happens on Windows if you rightclick->Edit with IDLE... a .py file - just don't use that.)
samwyse commentedon Aug 15, 2010
As it happens, I do use Windows and almost exclusively start IDLE via right-clicks on .py files. I've never seen the behavior you describe documented anywhere.
On Aug 15, 2010, at 1:37 PM, Cherniavsky Beni <report@bugs.python.org> wrote:
cben commentedon Aug 16, 2010
You're right, it wasn't.
[IDLE does show a "==== No Subprocess ====" line in the IDLE shell when you launch it this way. Unfortunately, the significance of this (and of the absence of "====== Restart ======" lines on F5) wouldn't be obvious unless you followed IDLE development around 2.3... :-(]
If you're using Python up to 2.6/3.0, please fall back to starting IDLE from the Start menu → Programs → Python X.Y → IDLE, then use File→Open to open files.
Or upgrade to Python 2.7/3.1, where right click → Edit with IDLE was fixed [bpo-5847] to open IDLE in the fully-functional mode. Note however, that once you have an open IDLE, still want to use File→Open or you'll get *2* IDLEs running at once, each with its own shell.
In both cases you'll notice IDLE will *completely* restart the underlying Python each time you press F5. This eliminates any stale-module problems, but kills all variables and state you had; this might require a change of habits but in my experience it's well worth it.
[P.S. If you absolutely must have module reloading without killing the whole state, and you're willing to debug occasional issues, take a look at http://www.cherrypy.org/attachment/wiki/AutoReload/autoreload.py
and possibly http://www.codexon.com/posts/a-better-python-reload]
serwy commentedon Dec 9, 2011
Should this issue be closed? It is related to bpo-4691.
samwyse commentedon Dec 20, 2011
[bpo-5847] fixed in 2.7/3.1