Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Terry Reedy Newsgroups: comp.lang.python Subject: Re: IDLE question: "you may still have to reload nested modules." Date: Sun, 6 Mar 2016 14:58:11 -0500 Lines: 67 Message-ID: References: <68500ae6-0e37-43d2-b8d8-f9fffef72d41@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de INsM4L3QfUYobeTWRScm0gMf55A9JefjOT1gf5VRgr1g== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:IDLE': 0.04; "'python": 0.07; 'restarting': 0.07; 'subject:question': 0.08; 'effect.': 0.09; 'imported': 0.09; 'interpreter,': 0.09; 'mode,': 0.09; 'modules.': 0.09; 'preferable': 0.09; 'python:': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'restarted': 0.09; 'subject:still': 0.09; 'python': 0.10; 'itself.': 0.11; 'jan': 0.11; 'interpreter': 0.15; '-n)': 0.16; '3.3.': 0.16; 'doc,': 0.16; 'guru': 0.16; 'hits': 0.16; 'idle.': 0.16; 'idlelib': 0.16; 'quoted': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'reedy': 0.16; 'reload': 0.16; 'selected.': 0.16; 'subject:may': 0.16; 'subprocess': 0.16; 'sys.modules': 0.16; 'wrote:': 0.16; 'nested': 0.18; 'creates': 0.18; 'gui': 0.18; 'shell': 0.18; 'tests': 0.18; 'runs': 0.18; 'changes': 0.20; 'affected': 0.22; 'file.': 0.22; 'am,': 0.23; 'chapter': 0.23; 'slightly': 0.23; 'import': 0.24; 'written': 0.24; 'header:In-Reply-To:1': 0.24; 'module': 0.25; 'header:User- Agent:1': 0.26; 'command': 0.26; 'header:X-Complaints-To:1': 0.26; 'entered': 0.27; '(e.g.': 0.27; 'separate': 0.27; 'question': 0.27; 'back.': 0.27; 'executing': 0.27; 'correct': 0.28; 'this.': 0.28; 'currently,': 0.29; 'itself,': 0.29; 'modified,': 0.29; 'restart': 0.29; 'environment': 0.29; 'reset': 0.29; 'starts': 0.29; 'code': 0.30; 'initially': 0.30; 'normally': 0.30; 'window': 0.30; 'option': 0.31; 'statement': 0.32; 'run': 0.33; 'changed': 0.33; 'clarify': 0.33; 'closely': 0.33; 'foo': 0.33; 'idle': 0.33; 'option.': 0.33; 'editor': 0.34; 'file': 0.34; 'running': 0.34; 'next': 0.35; 'could': 0.35; 'attempt': 0.35; 'fresh': 0.35; 'saved': 0.35; 'comment': 0.35; 'but': 0.36; 'list,': 0.36; 'should': 0.36; 'there': 0.36; 'loaded': 0.36; 'modules': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'being': 0.37; 'received:org': 0.37; 'missing': 0.37; '(with': 0.38; 'difference': 0.38; "won't": 0.38; 'version': 0.38; 'files': 0.38; 'does': 0.39; 'to:addr:python.org': 0.40; 'mark': 0.40; 'still': 0.40; 'your': 0.60; 'default': 0.61; 'email addr:gmail.com': 0.62; 'received:96': 0.63; 'between': 0.65; 'restore': 0.70; 'book,': 0.72; 'subject:have': 0.80; 'actions,': 0.84; 'have?': 0.84; 'possible."': 0.84; 'subject:you': 0.85; 'received:fios.verizon.net': 0.91; 'technically': 0.91; 'confirms': 0.95 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: pool-96-227-207-81.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 In-Reply-To: <68500ae6-0e37-43d2-b8d8-f9fffef72d41@googlegroups.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:104172 On 3/6/2016 7:24 AM, alien2utoo@gmail.com wrote: > Hello list, > > I am following "Learning Python: Mark Lutz" and came across following > in chapter 3 few days back. What is the copyright date on the copy you have? > [quote] * You may still have to reload nested modules. Technically > speaking, IDLE's Run->Run Module menu option always runs the current > version of the top-level file only; imported files may still need to > be interactively reloaded when changed. ... [/quote] > > It is slightly confusing, as to what it does imply. Could any IDLE > guru clarify if I am missing or overlooking something? IDLE currently, in its default mode, runs a module in a fresh separate process with a fresh sys.modules. It closely simulates running a module from the command line with 'python -m mymodule'. (One difference is that sys.modules is initially larger when run by IDLE.) The quoted statement must have been written when IDLE always ran user code in the persistent IDLE process, as it still does if one starts IDLE with the -n option. The current IDLE doc, in section 3.3. 'Running without a subprocess' (with -n) ends with "Also, the environment is not restarted when Run/Run Module (F5) is selected. If your code has been modified, you must reload() the affected modules and re-import any specific items (e.g. from foo import baz) if the changes are to take effect. For these reasons, it is preferable to run IDLE with the default subprocess if at all possible." Even if there were an attempt to restore sys.modules on F5, the comment would still apply if one edited and saved an stdlib module imported by IDLE. I run into this when I edit an idlelib file. I can run tests on the file in a separate process with F5, but to verify that the edit has the intended effect on IDLE itself, I have to restart IDLE itself. If the quoted statement is in the most recent version of the book, it should be changed in the next one. > If a needed-by-top-level-file module was changed after 'Run->Run > Module', it would any way need to be reloaded. > > If it was changed between two "Run->Run Module" actions, won't it be > automatically loaded afresh as a part of restarting Python > interpreter and executing top-level-file [where is the question of > reloading then?]? > > [Side observation: though F5 or "Run->Run Module" restarts Python > interpreter with top-level-file afresh [indicated by dir() content > before and after], the command history is not reset during this. Commands are entered into and kept in the Shell in the IDLE process. There are not erased unless one closes Shell. If there is an editor window that keeps IDLE running, and one hits F5, IDLE creates a new Shell with no history. > This > likely confirms the GUI process being separate than interpreter.] The GUI process has its own interpreter, but you are correct that the user interpreter is normally separate. -- Terry Jan Reedy