This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Reload Python modules when running programs
Type: enhancement Stage: resolved
Components: IDLE Versions: Python 3.2
process
Status: closed Resolution: duplicate
Dependencies: Superseder: IDLE/Win Installer: drop -n switch for 2.7/3.1; install 3.1 as idle3
View: 5847
Assigned To: kbk Nosy List: cben, kbk, roger.serwy, samwyse
Priority: normal Keywords:

Created on 2009-06-22 05:30 by samwyse, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (6)
msg89593 - (view) Author: Samwyse (samwyse) * Date: 2009-06-22 05:30
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.
msg113989 - (view) Author: Cherniavsky Beni (cben) * Date: 2010-08-15 18:37
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.)
msg114017 - (view) Author: Samwyse (samwyse) * Date: 2010-08-15 22:19
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:

> 
> Cherniavsky Beni <cben@users.sf.net> added the comment:
> 
> 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.)
> 
> ----------
> nosy: +cben
> 
> _______________________________________
> Python tracker <report@bugs.python.org>
> <http://bugs.python.org/issue6321>
> _______________________________________
msg114032 - (view) Author: Cherniavsky Beni (cben) * Date: 2010-08-16 00:38
> 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 [issue5847] 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]
msg149069 - (view) Author: Roger Serwy (roger.serwy) * (Python committer) Date: 2011-12-09 01:42
Should this issue be closed? It is related to #4691.
msg149919 - (view) Author: Samwyse (samwyse) * Date: 2011-12-20 17:34
[issue5847] fixed in 2.7/3.1
History
Date User Action Args
2022-04-11 14:56:50adminsetgithub: 50570
2011-12-21 06:58:21ned.deilysetresolution: out of date -> duplicate
superseder: IDLE/Win Installer: drop -n switch for 2.7/3.1; install 3.1 as idle3
stage: resolved
2011-12-20 17:34:12samwysesetstatus: open -> closed
resolution: out of date
messages: + msg149919
2011-12-09 01:42:56roger.serwysetnosy: + roger.serwy
messages: + msg149069
2010-08-16 00:38:36cbensetmessages: + msg114032
2010-08-15 22:19:34samwysesetmessages: + msg114017
2010-08-15 18:37:09cbensetnosy: + cben
messages: + msg113989
2010-07-10 12:19:03BreamoreBoysetassignee: kbk
versions: + Python 3.2, - Python 3.0
nosy: + kbk
2009-06-22 05:30:19samwysecreate