Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #81356
| Path | csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <ian.g.kelly@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.012 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; 'interpreter.': 0.07; '22,': 0.09; 'referenced': 0.09; 'subject:module': 0.09; 'testing,': 0.09; 'python': 0.11; '"_"': 0.16; '23,': 0.16; 'determining': 0.16; 'evaluating': 0.16; 'subject:created': 0.16; 'unload': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'variable': 0.18; 'module': 0.19; 'patrick': 0.19; '>>>': 0.22; 'import': 0.22; 'references': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'returned': 0.30; 'message-id:@mail.gmail.com': 0.30; 'subject:skip:i 10': 0.31; 'maybe': 0.34; 'subject:with': 0.35; 'created': 0.35; 'received:google.com': 0.35; 'module.': 0.36; 'nov': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'how': 0.40; 'deleting': 0.60; 'expression': 0.60; 'ian': 0.60; 'new': 0.61; "you're": 0.61; 'special': 0.74; 'deleted?': 0.84; 'hanging': 0.84; 'it\xe2\x80\x99s': 0.84 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; bh=KeefwESSwSRISirJP0BufGkeKeuwjfjN6GJJgu5uEDI=; b=RJEvmoQ33M2+xokJlveGy4FG7F5v3OD9ES3tS3ARRf6kPTAKa5cYeyDSsYIyPSe83A 3WqY9dmhyhc+wxOqQWFy/IwGA3T7tNz/2VL+DdKzZqYBCJl835tRsh2Ku10IyA1u5wOf /IzgNfO5xqtyakBUHTmmyY+L2c9UavEmMoNVkhVozFVUWyWW/+RW4twtdpcykVbjfX/H 7m20RJIDk0tyfYTNu79OZUREhY+/QEpZlep8oc1WVRDGC60zizfdojgksbQqboOVEevn 7vxhUbOJ07wHStywvdOIhvn3dNykPXbkQufRvYy3z6ZNiSXvdoS8xMyi/wcJ/LV1rpUx fhfQ== |
| X-Received | by 10.68.107.162 with SMTP id hd2mr22178613pbb.145.1416736634279; Sun, 23 Nov 2014 01:57:14 -0800 (PST) |
| MIME-Version | 1.0 |
| In-Reply-To | <CALwzidnHV8smFHtvixtdhX-i94PWbwNKSRrR6HAfhn2HOKqxsw@mail.gmail.com> |
| References | <C093BC09-3AB7-49DB-B160-265A34C6BCDA@gmail.com> <CALwzidnHV8smFHtvixtdhX-i94PWbwNKSRrR6HAfhn2HOKqxsw@mail.gmail.com> |
| From | Ian Kelly <ian.g.kelly@gmail.com> |
| Date | Sun, 23 Nov 2014 02:56:34 -0700 |
| Subject | Re: unloading a module created with imp.new_module |
| To | Python <python-list@python.org> |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | quoted-printable |
| 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.16178.1416736637.18130.python-list@python.org> (permalink) |
| Lines | 34 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1416736637 news.xs4all.nl 2938 [2001:888:2000:d::a6]:47964 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:81356 |
Show key headers only | View raw
On Sun, Nov 23, 2014 at 2:48 AM, Ian Kelly <ian.g.kelly@gmail.com> wrote:
> On Sat, Nov 22, 2014 at 11:49 PM, Patrick Stinson <patrickkidd@gmail.com> wrote:
>> If I create a module with imp.new_module(name), how can I unload it so that all the references contained in it are set to zero and the module is deleted? deleting the reference that is returned doesn’t seem to do the job, and it’s not in sys.modules, so where is the dangling reference?
>
> How are you determining that the module is not deleted?
>From my testing, using Python 3.4:
>>> for i in range(5): imp.new_module('spam')
...
<module 'spam'>
<module 'spam'>
<module 'spam'>
<module 'spam'>
<module 'spam'>
>>> import gc, types
>>> [m for m in gc.get_objects() if isinstance(m, types.ModuleType) and m.__name__ == 'spam']
[<module 'spam'>]
>>> 42
42
>>> [m for m in gc.get_objects() if isinstance(m, types.ModuleType) and m.__name__ == 'spam']
[]
In this case one of the created modules was hanging around because it
was still referenced by the special "_" variable of the interactive
interpreter. Evaluating a new expression cleared that out and deleted
the module. Maybe you're seeing the same thing.
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: unloading a module created with imp.new_module Ian Kelly <ian.g.kelly@gmail.com> - 2014-11-23 02:56 -0700
csiph-web