Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.albasani.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.013 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'cpython': 0.05; 'ignored': 0.07; 'subject:module': 0.09; 'cc:addr:python-list': 0.11; 'gui': 0.12; '24,': 0.16; '__del__': 0.16; 'builtins.': 0.16; 'dict': 0.16; 'function?': 0.16; 'garbage': 0.16; 'globals': 0.16; "module's": 0.16; 'objects?': 0.16; 'subject:created': 0.16; 'substitute': 0.16; 'wow,': 0.16; 'appropriate': 0.16; 'wrote:': 0.18; 'module': 0.19; 'memory': 0.22; 'import': 0.22; 'email addr:gmail.com>': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'helpful': 0.24; 'question': 0.24; 'cc:2**0': 0.24; 'script': 0.25; '>': 0.26; 'references': 0.26; 'header:In- Reply-To:1': 0.27; 'function': 0.29; 'testing': 0.29; 'am,': 0.29; 'url:mailman': 0.30; 'code': 0.31; 'embedding': 0.31; 'subject:skip:i 10': 0.31; 'class': 0.32; 'this.': 0.32; 'know.': 0.32; 'another': 0.32; 'url:python': 0.33; 'becomes': 0.33; 'call.': 0.33; 'guess': 0.33; 'maybe': 0.34; 'could': 0.34; 'subject:with': 0.35; 'test': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'url:listinfo': 0.36; 'doing': 0.36; 'method': 0.36; 'possible': 0.36; 'url:org': 0.36; 'being': 0.38; 'message- id:@gmail.com': 0.38; 'nov': 0.38; 'does': 0.39; 'expensive': 0.39; 'itself': 0.39; 'though,': 0.39; 'url:mail': 0.40; 'how': 0.40; 'ian': 0.60; 'strictly': 0.61; 'header:Message-Id:1': 0.63; 'to:addr:gmail.com': 0.65; 'production': 0.68; 'panel': 0.68; 'funny': 0.74; '2014,': 0.84; 'beside': 0.84; 'concept.': 0.84; 'i\xe2\x80\x99ll': 0.84; 'careful': 0.91; 'comfort': 0.96 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:mime-version:subject:from:in-reply-to:date:cc :message-id:references:to; bh=RQ8tcuN4GVsjCwZlf+YSWHIis5evTCdQked/e3X9etY=; b=c7lEspMawIIi7XsQPVLmsp/S/fz52NevQ9GRwoosW3tNZ+NGFFSzlfx37uqFTgzXKR UvqtLbHpmSHfZHLLHeigUsoP2ekpuN/L/yurEFq1OF5LU9W7wb2sFA+J/aaxs8qbU6n9 igoxP7rOb1HJm3Vf/kLcm0SJMxlYchG7ZkkMTlJu6SqWJIBToEoi8+w3It7hiLs8Np4n tvUVt+3rN9L0i0IetaH8CA8RwE2gwJNS+1KtcQyGjsWJx1REaEduSZ0H2d+DgmHEfWVW IzmVLwWI5PrvQajoK1svoUxDTZJwWVvNUuEascD9lkZbNh1YRZTKQUwBWcMz4okiOoEr vjWA== X-Received: by 10.68.163.65 with SMTP id yg1mr39533237pbb.21.1416898109628; Mon, 24 Nov 2014 22:48:29 -0800 (PST) Content-Type: multipart/alternative; boundary="Apple-Mail=_B5F64B8C-FA74-40E9-8C48-4D7C27F48A76" Mime-Version: 1.0 (Mac OS X Mail 8.1 \(1993\)) Subject: Re: unloading a module created with imp.new_module From: Patrick Stinson In-Reply-To: Date: Mon, 24 Nov 2014 21:48:27 -0900 References: <6E80C5B3-4203-4CA5-9796-175DB9567862@gmail.com> To: Ian Kelly X-Mailer: Apple Mail (2.1993) Cc: Python 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: 95 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1416898113 news.xs4all.nl 2929 [2001:888:2000:d::a6]:43355 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:81488 --Apple-Mail=_B5F64B8C-FA74-40E9-8C48-4D7C27F48A76 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Nov 24, 2014, at 6:12 AM, Ian Kelly wrote: >=20 >=20 > On Nov 24, 2014 1:27 AM, "Patrick Stinson" > wrote: > > > > How does the __del__ method have a reference to the module=E2=80=99s = globals dict? because it references the print function? >=20 > The module's dict becomes the __globals__ dict used by the function = for looking up globals and builtins. >=20 Wow, that=E2=80=99s very helpful and good to know. Funny I never ran = into that when doing this via an extensive CPython embedding project. Or = maybe I ignored it. > > Crazy. Is there any other way to comfort when a module is being = deleted beside defining a class object with a printing dtor? >=20 > Modules don't strictly have to be ModuleType. You could substitute a = class with a __del__ method for the module itself for testing this. Be = careful with leaving this in your production code though, as the = presence of __del__ methods can interfere with garbage collection and = are not advisable prior to 3.4. >=20 > You can also test whether an object is still in memory by looking for = it in gc.get_objects() although be warned that is an expensive call. >=20 Interesting concept. One thing I am doing is allowing one script to = import another by name. So in my gui I=E2=80=99ll have a panel for each = script with a line edit to set the name, which then generates an = appropriate slug. Is it still possible to import non-module objects? I = guess this question is just for fun now :) > --=20 > https://mail.python.org/mailman/listinfo/python-list --Apple-Mail=_B5F64B8C-FA74-40E9-8C48-4D7C27F48A76 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8

On Nov 24, 2014, at 6:12 AM, = Ian Kelly <ian.g.kelly@gmail.com> wrote:


On Nov 24, 2014 1:27 AM, "Patrick Stinson" <patrickkidd@gmail.com> wrote:
>
> How does the __del__ method have a reference to the module=E2=80=99s = globals dict? because it references the print function?

The module's dict becomes the __globals__ dict used by the = function for looking up globals and builtins.

Wow, that=E2=80=99s very helpful = and good to know. Funny I never ran into that when doing this via an = extensive CPython embedding project. Or maybe I ignored = it.

> Crazy. Is there any other way to comfort = when a module is being deleted beside defining a class object with a = printing dtor?

Modules don't strictly have = to be ModuleType. You could substitute a class with a __del__ method for = the module itself for testing this. Be careful with leaving this in your = production code though, as the presence of __del__ methods can interfere = with garbage collection and are not advisable prior to 3.4.

You can also test whether an object is still in = memory by looking for it in gc.get_objects() although be warned that is = an expensive call.

Interesting = concept. One thing I am doing is allowing one script to import another = by name. So in my gui I=E2=80=99ll have a panel for each script with a = line edit to set the name, which then generates an appropriate slug. Is = it still possible to import non-module objects? I guess this question is = just for fun now :)



= --Apple-Mail=_B5F64B8C-FA74-40E9-8C48-4D7C27F48A76--