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: 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: References: From: Ian Kelly Date: Sun, 23 Nov 2014 02:56:34 -0700 Subject: Re: unloading a module created with imp.new_module To: Python 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On Sun, Nov 23, 2014 at 2:48 AM, Ian Kelly wrote: > On Sat, Nov 22, 2014 at 11:49 PM, Patrick Stinson = wrote: >> If I create a module with imp.new_module(name), how can I unload it so t= hat all the references contained in it are set to zero and the module is de= leted? deleting the reference that is returned doesn=E2=80=99t seem to do t= he job, and it=E2=80=99s not in sys.modules, so where is the dangling refer= ence? > > 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') ... >>> import gc, types >>> [m for m in gc.get_objects() if isinstance(m, types.ModuleType) and m._= _name__ =3D=3D 'spam'] [] >>> 42 42 >>> [m for m in gc.get_objects() if isinstance(m, types.ModuleType) and m._= _name__ =3D=3D '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.