Skip to content

Reload Python modules when running programs #50570

Closed

Description

@samwyse
mannequin
BPO 6321
Nosy @kbkaiser, @cben, @serwy
Superseder
  • bpo-5847: IDLE/Win Installer: drop -n switch for 2.7/3.1; install 3.1 as idle3
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/kbkaiser'
    closed_at = <Date 2011-12-20.17:34:12.718>
    created_at = <Date 2009-06-22.05:30:18.670>
    labels = ['expert-IDLE', 'type-feature']
    title = 'Reload Python modules when running programs'
    updated_at = <Date 2011-12-21.06:58:21.383>
    user = 'https://bugs.python.org/samwyse'

    bugs.python.org fields:

    activity = <Date 2011-12-21.06:58:21.383>
    actor = 'ned.deily'
    assignee = 'kbk'
    closed = True
    closed_date = <Date 2011-12-20.17:34:12.718>
    closer = 'samwyse'
    components = ['IDLE']
    creation = <Date 2009-06-22.05:30:18.670>
    creator = 'samwyse'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 6321
    keywords = []
    message_count = 6.0
    messages = ['89593', '113989', '114017', '114032', '149069', '149919']
    nosy_count = 4.0
    nosy_names = ['kbk', 'cben', 'samwyse', 'roger.serwy']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '5847'
    type = 'enhancement'
    url = 'https://bugs.python.org/issue6321'
    versions = ['Python 3.2']

    Activity

    1. samwyse commented on Jun 22, 2009

      samwysemannequin
      MannequinAuthor

      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.

    2. added
      type-feature
      on Jun 22, 2009
    3. cben commented on Aug 15, 2010

      cbenmannequin
      Mannequin

      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.)

    4. samwyse commented on Aug 15, 2010

      samwysemannequin
      MannequinAuthor

      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\>


    5. cben commented on Aug 16, 2010

      cbenmannequin
      Mannequin

      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]

    6. serwy commented on Dec 9, 2011

      serwymannequin
      Mannequin

      Should this issue be closed? It is related to bpo-4691.

    7. samwyse commented on Dec 20, 2011

      samwysemannequin
      MannequinAuthor

      [bpo-5847] fixed in 2.7/3.1

    8. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    Labels

    topic-IDLEtype-feature

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions