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


Groups > comp.lang.python > #81453

Re: unloading a module created with imp.new_module

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.005
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'heavily': 0.04; 'model,': 0.05; 'back-end': 0.09; 'classes.': 0.09; 'objects,': 0.09; 'subject:module': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; '24,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'loop.': 0.16; 'modules,': 0.16; 'reload': 0.16; 'subject:created': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'code,': 0.22; 'cc:addr:python.org': 0.22; 'mon,': 0.24; 'cc:2**0': 0.24; 'class.': 0.26; 'header:In-Reply-To:1': 0.27; 'quickly': 0.29; 'moved': 0.30; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'usually': 0.31; 'subject:skip:i 10': 0.31; 'class': 0.32; 'run': 0.32; 'updated': 0.34; 'subject:with': 0.35; 'classes': 0.35; 'objects': 0.35; 'received:google.com': 0.35; 'done': 0.36; 'possible': 0.36; 'two': 0.37; 'being': 0.38; 'nov': 0.38; 'pm,': 0.38; 'users': 0.40; 'even': 0.60; 'matter': 0.61; 'simple': 0.61; 'refer': 0.63; 'places': 0.64; 'kept': 0.65; 'batchelder': 0.84; 'persistent': 0.84; 'to:none': 0.92
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 :content-type; bh=2JmDD0EsKFAV/uNE49jh/ijfBv0pDPd+aEXnTAhsjmg=; b=lIBcc9bI53nS20MQ6V9dXNVoDlwrEoVZE8GQclZti3hG3edhQjzE5YSWdVOE6ehf6X Ok6jwrKeJ8Jr8Lc6gAdve0ZeOtOJ10X38hCBaFwxEfYasmlCJufewrrRiTXBGmZk+IIw rJHSGgp5qIkWvZiLSns91tEIvCU73zEfh0SUHnR/jn1fvmTKwZQKwqlD46Jfx3p1KOVA kJuTdBfogPPnMoDQjtQoSpW9NH9DYNiCQvs1a1rPaHrcsXC3f9ngvhpEkqFz1Z0bcNM5 lqsLQtcaxbRwEP1lKmm7zBRKMRgk6LyeB9raMnmRzRFZojhqpRXWqrvYCYzcevOGx+np dNdQ==
MIME-Version 1.0
X-Received by 10.107.136.92 with SMTP id k89mr17658989iod.43.1416834387834; Mon, 24 Nov 2014 05:06:27 -0800 (PST)
In-Reply-To <m4v4c5$2la$1@ger.gmane.org>
References <C093BC09-3AB7-49DB-B160-265A34C6BCDA@gmail.com> <m4u6o4$76f$1@ger.gmane.org> <B23B77C2-CE6A-4921-A651-F1A2119EB992@gmail.com> <m4v4c5$2la$1@ger.gmane.org>
Date Tue, 25 Nov 2014 00:06:27 +1100
Subject Re: unloading a module created with imp.new_module
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
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>
Newsgroups comp.lang.python
Message-ID <mailman.16247.1416834390.18130.python-list@python.org> (permalink)
Lines 17
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1416834390 news.xs4all.nl 2937 [2001:888:2000:d::a6]:44051
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:81453

Show key headers only | View raw


On Mon, Nov 24, 2014 at 10:21 PM, Ned Batchelder <ned@nedbatchelder.com> wrote:
> Keep in mind that Python object have a reference to their class. If your
> users are defining classes in their modules, and you instantiate the class
> to create objects, then even when you reload updated code, the old objects
> will still refer to the old classes.  This is one of the things that makes
> reloading modules in Python so difficult.

Yes, which is why I actually moved right away from that model, in two
projects that are built heavily around code reloading. In both cases,
code is all done as simple functions which run and then finish, and
everything returns as quickly as possible to a main back-end loop. All
persistent state is kept in code-free data structures, usually
key-based mappings of various sorts, with instantiable objects being
used only in places where it won't matter if they keep using the old
code.

ChrisA

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


Thread

Re: unloading a module created with imp.new_module Chris Angelico <rosuav@gmail.com> - 2014-11-25 00:06 +1100

csiph-web