Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #103725

Re: Reason for not allowing import twice but allowing reload()

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Subject Re: Reason for not allowing import twice but allowing reload()
Date Tue, 1 Mar 2016 03:05:24 +1100
Lines 32
Message-ID <mailman.18.1456761926.20602.python-list@python.org> (permalink)
References <645cdd46-d4a4-49b3-a0d8-848608d70d73@googlegroups.com> <CALwzidnouPmT26-VZsGpoqojM92yZzY5+DSLta5fCqop1YNoUg@mail.gmail.com> <mailman.10.1456729896.2321.python-list@python.org> <nb1o6u$i6e$1@dont-email.me>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
X-Trace news.uni-berlin.de zSZXhL0TR2PziWlZqq3Jrg8Nsw2YG5nLgnAb4ffKkjMg==
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.006
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'cc:addr:python-list': 0.09; 'definition,': 0.09; 'effect.': 0.09; 'subject:()': 0.09; 'python': 0.10; 'python.': 0.11; 'subject:not': 0.11; 'importing': 0.15; '"exec"': 0.16; '"import"': 0.16; '.py': 0.16; '2016': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'library"': 0.16; 'permits': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:import': 0.16; 'wrote:': 0.16; 'gui': 0.18; 'language': 0.19; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'work,': 0.21; 'latter': 0.22; 'am,': 0.23; 'code.': 0.23; '(where': 0.23; '(this': 0.24; 'header:In- Reply-To:1': 0.24; 'module': 0.25; "doesn't": 0.26; 'command': 0.26; 'rest': 0.26; 'connected': 0.27; 'message- id:@mail.gmail.com': 0.27; 'regular': 0.29; '(it': 0.29; 'really,': 0.29; 'restart': 0.29; 'code': 0.30; 'probably': 0.31; "can't": 0.32; 'changed': 0.33; 'useful': 0.33; 'loading': 0.33; 'tue,': 0.34; 'file': 0.34; 'running': 0.34; 'server': 0.34; 'received:google.com': 0.35; 'done': 0.35; 'something': 0.35; 'but': 0.36; 'should': 0.36; 'received:209.85': 0.36; 'modules': 0.36; 'subject:: ': 0.37; 'received:209.85.213': 0.37; 'doing': 0.38; 'received:209': 0.38; 'drop': 0.38; 'application': 0.39; 'rather': 0.39; 'clients': 0.61; 'more': 0.63; 'between': 0.65; 'mar': 0.65; 'believe': 0.66; 'date,': 0.66; 'notices': 0.66; 'situation': 0.67; 'talking': 0.67; 'chrisa': 0.84; "it'd": 0.84; "op's": 0.84; 'to:none': 0.91; 'technique': 0.93
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc; bh=PILXXHirY9aV2b4CRNZSqrjJM1/muzltB0mZwlCkF7k=; b=hPvjm1yN/t/8mf+/o8sEFJVE3TLbTZ3OzvmYp/UQ59sjL0dvboVYFQdVv8QVMLZJiX PdKCqzYP2ZS16TTmH7fpGjjijJf8dLAOqffQ1zRFRYWmc+rT23KUMkjFwMQ8gvn1cp5D 4dv9vt1/FsNXm+PqeomZQ8O7JWB4f7SLpB6RfveLz5XvzzACE2/z+DBBMorCWL5pyEi7 zCfOZuuCabmbSUh1Nu5TQ3jV0EIHzoQEqONzfjQVHSWuoPb5f49fhHPGZFgDI/JUOntJ rwCehwuqAp1cPHlI98j66KhSJ80J63yduuABz24IAfS/weV9PvGotpWSuNRQx+1q9piu iqmw==
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:cc; bh=PILXXHirY9aV2b4CRNZSqrjJM1/muzltB0mZwlCkF7k=; b=D/j0yEUjTU3cMAOs94VSHs1gWBk9usz0lrpsJvJNCdvjlzS5KNJ0Y2uWjKaCEaXS9h w4I7aPiWnNH+2Lgo1KoGFrz95jvqVO5Yexv5PXfaXAplEGsmBXYqJoPz6ZT/62+pA2wJ eI55648INGBsXe0LKZRc57KCd23P9/Mh1ogbh4yyv0+oY8r24QBZLfrsB7N7SOUO+GXk yd6noR/S9gauBwvcCu0SxhNwuykApk6SnjZfu9+FySuKEQXKsO/xJE7G7ToTU2EXR5Ha us38785XLyZl2fLmQwIYzB71QVP2w8Jr1lbuztkW2TvE+/hRsr8DKsOkjfVRm1rNnqEm BTfA==
X-Gm-Message-State AD7BkJIBa5HZjam13xiwETZBqvlcpDDo6Xz36G8j/jUdkHmJ5OzBuGMCEV3NX+7u643gTvqK5kTghmxbd/mLNQ==
X-Received by 10.50.28.105 with SMTP id a9mr11189266igh.94.1456761924169; Mon, 29 Feb 2016 08:05:24 -0800 (PST)
In-Reply-To <nb1o6u$i6e$1@dont-email.me>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.21
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Xref csiph.com comp.lang.python:103725

Show key headers only | View raw


On Tue, Mar 1, 2016 at 2:33 AM, BartC <bc@freeuk.com> wrote:
>> I think the OP's talking more about the situation of having an active
>> session (IDLE was mentioned), importing a local module (a .py file
>> from the current directory), then editing the file and re-importing,
>> which has no effect. While I am sympathetic to the problem, I don't
>> believe the language should be changed here; what might be useful is
>> something that notices that an already-loaded module is now out of
>> date, but really, the best solution is a change of workflow that no
>> longer has long-running modules loading live-updated code.
>
>
> Not in Python (this was pre-Python actually) but I once used such a
> technique all the time.
>
> The main set of modules would be running a GUI application which also had a
> command line.

I use this technique all the time, in current code. But not in Python.
The main reason is to have a server that permits clients to connect
and remain connected, and to update code in ways that affect those
connected clients. So by definition, I can't restart the server (it
would drop the connections), and the critical main loop doesn't
reload, but all the rest of the code does. It's pretty much the same
style you had.

Doing the same thing in Python would probably best be done using
"exec" rather than "import". It'd work, but you'd have to
differentiate in code between "load this module which can be reloaded"
and "import this module from the standard library" (where the latter
would be the regular "import" statement).

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Reason for not allowing import twice but allowing reload() alien2utoo@gmail.com - 2016-02-28 22:40 -0800
  Re: Reason for not allowing import twice but allowing reload() Chris Angelico <rosuav@gmail.com> - 2016-02-29 18:01 +1100
    Re: Reason for not allowing import twice but allowing reload() Steven D'Aprano <steve@pearwood.info> - 2016-03-01 22:18 +1100
      Re: Reason for not allowing import twice but allowing reload() Chris Angelico <rosuav@gmail.com> - 2016-03-01 22:39 +1100
        Re: Reason for not allowing import twice but allowing reload() Steven D'Aprano <steve@pearwood.info> - 2016-03-02 04:11 +1100
          Re: Reason for not allowing import twice but allowing reload() Chris Angelico <rosuav@gmail.com> - 2016-03-02 05:04 +1100
      Re: Reason for not allowing import twice but allowing reload() Ian Kelly <ian.g.kelly@gmail.com> - 2016-03-01 14:53 -0700
      Re: Reason for not allowing import twice but allowing reload() Chris Angelico <rosuav@gmail.com> - 2016-03-02 09:02 +1100
      Re: Reason for not allowing import twice but allowing reload() Ian Kelly <ian.g.kelly@gmail.com> - 2016-03-01 15:29 -0700
        Re: Reason for not allowing import twice but allowing reload() Steven D'Aprano <steve@pearwood.info> - 2016-03-02 12:19 +1100
          Re: Reason for not allowing import twice but allowing reload() Ian Kelly <ian.g.kelly@gmail.com> - 2016-03-01 19:22 -0700
            Re: Reason for not allowing import twice but allowing reload() Rustom Mody <rustompmody@gmail.com> - 2016-03-02 02:15 -0800
              Re: Reason for not allowing import twice but allowing reload() Rustom Mody <rustompmody@gmail.com> - 2016-03-02 02:19 -0800
            Re: Reason for not allowing import twice but allowing reload() Grant Edwards <invalid@invalid.invalid> - 2016-03-02 15:15 +0000
      Re: Reason for not allowing import twice but allowing reload() Chris Angelico <rosuav@gmail.com> - 2016-03-02 11:13 +1100
  Re: Reason for not allowing import twice but allowing reload() Ian Kelly <ian.g.kelly@gmail.com> - 2016-02-29 00:02 -0700
  Re: Reason for not allowing import twice but allowing reload() Chris Angelico <rosuav@gmail.com> - 2016-02-29 18:11 +1100
    Re: Reason for not allowing import twice but allowing reload() BartC <bc@freeuk.com> - 2016-02-29 15:33 +0000
      Re: Reason for not allowing import twice but allowing reload() Chris Angelico <rosuav@gmail.com> - 2016-03-01 03:05 +1100
  Correct IDLE usage (was Reason for not allowing import twice but allowing reload()) Rustom Mody <rustompmody@gmail.com> - 2016-02-29 04:42 -0800
    Re: Correct IDLE usage (was Reason for not allowing import twice but allowing reload()) Terry Reedy <tjreedy@udel.edu> - 2016-03-01 01:52 -0500
      Re: Correct IDLE usage (was Reason for not allowing import twice but allowing reload()) Rustom Mody <rustompmody@gmail.com> - 2016-03-02 07:22 -0800
        Re: Correct IDLE usage (was Reason for not allowing import twice but allowing reload()) Terry Reedy <tjreedy@udel.edu> - 2016-03-02 21:40 -0500
          Re: Correct IDLE usage (was Reason for not allowing import twice but allowing reload()) Rustom Mody <rustompmody@gmail.com> - 2016-03-02 20:07 -0800
            Re: Correct IDLE usage (was Reason for not allowing import twice but allowing reload()) Rustom Mody <rustompmody@gmail.com> - 2016-03-02 20:17 -0800
  Re: Reason for not allowing import twice but allowing reload() alien2utoo@gmail.com - 2016-02-29 05:00 -0800
  Re: Reason for not allowing import twice but allowing reload() alien2utoo@gmail.com - 2016-02-29 05:22 -0800
    Re: Reason for not allowing import twice but allowing reload() alien2utoo@gmail.com - 2016-02-29 05:25 -0800
      Re: Reason for not allowing import twice but allowing reload() Steven D'Aprano <steve@pearwood.info> - 2016-03-02 04:00 +1100
        Re: Reason for not allowing import twice but allowing reload() alien2utoo@gmail.com - 2016-03-05 04:51 -0800
          Re: Reason for not allowing import twice but allowing reload() Steven D'Aprano <steve@pearwood.info> - 2016-03-10 00:53 +1100
    Reason for not allowing import twice but allowing reload() Rustom Mody <rustompmody@gmail.com> - 2016-02-29 05:51 -0800
      Re: Reason for not allowing import twice but allowing reload() alien2utoo@gmail.com - 2016-02-29 07:13 -0800
    Re: Reason for not allowing import twice but allowing reload() Terry Reedy <tjreedy@udel.edu> - 2016-03-01 02:04 -0500
  Re: Reason for not allowing import twice but allowing reload() alien2utoo@gmail.com - 2016-03-06 00:20 -0800
    Re: Reason for not allowing import twice but allowing reload() Steven D'Aprano <steve@pearwood.info> - 2016-03-07 01:50 +1100
  Re: Reason for not allowing import twice but allowing reload() alien2utoo@gmail.com - 2016-03-06 00:31 -0800

csiph-web