Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed3a.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.020 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'interpreter': 0.05; 'output': 0.05; 'class,': 0.07; 'subject:module': 0.09; 'cc:addr :python-list': 0.11; '.py': 0.16; '23,': 0.16; '__del__': 0.16; 'function?': 0.16; 'garbage': 0.16; 'globals': 0.16; "module's": 0.16; 'subject:created': 0.16; 'wrote:': 0.18; 'module': 0.19; 'email addr:gmail.com>': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'instance,': 0.24; 'file.': 0.24; 'cc:2**0': 0.24; '>': 0.26; 'references': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'am,': 0.29; 'url:mailman': 0.30; 'subject:skip:i 10': 0.31; 'class': 0.32; 'run': 0.32; 'url:python': 0.33; 'subject:with': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'done': 0.36; 'url:listinfo': 0.36; 'method': 0.36; 'url:org': 0.36; 'being': 0.38; 'message-id:@gmail.com': 0.38; 'nov': 0.38; 'pm,': 0.38; 'does': 0.39; 'itself': 0.39; 'skip:p 20': 0.39; 'url:mail': 0.40; 'how': 0.40; 'ian': 0.60; 'back': 0.62; 'header:Message-Id:1': 0.63; 'skip:\xe2 10': 0.65; 'to:addr:gmail.com': 0.65; 'here': 0.66; 'between': 0.67; '2014,': 0.84; 'beside': 0.84; 'dict,': 0.84; '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=eQh0+B9NrbwhnTSkKbRvI+cj0NVTFRagmRaI3hbJm0A=; b=PrH/2mNYCRcGzuQ6hZ/j2ZS50NrVJlRWkW4hjh0B0P1h835e7fTIHbd8Rt6zB9Jw9Y 03ckT9AuHg6NwFOruEEcOJyITLmEJHUUQuoveLmN/cDDUBDt5qcce8JJsLdKsCxCV4hB YQ+kVBamtRWzDuNwjGAqdJCG/QZN2WZXl/W0suOPn+LFrcGD7MbjS5l27NSDucrraqlS 3T9GgO4uI6LIfgoO+UkP+GGmlqMpNZ0pdZppGtRB4XYD2aO1DqAH6kqSKa58ZFke+aU8 HFCU7A+pRj1VLmet+8qIRGqp9CiWC4LkGoRSosxxg7Ds4pl9hFL7RCbh1oU2kmM9fzcM k7ag== X-Received: by 10.70.36.15 with SMTP id m15mr30713985pdj.132.1416814038207; Sun, 23 Nov 2014 23:27:18 -0800 (PST) Content-Type: multipart/alternative; boundary="Apple-Mail=_425D012F-63AF-4AD3-B5F2-35BFC73C768E" 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: Sun, 23 Nov 2014 22:27:16 -0900 References: To: Ian Kelly X-Mailer: Apple Mail (2.1993) X-Mailman-Approved-At: Mon, 24 Nov 2014 09:16:01 +0100 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: 98 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1416816962 news.xs4all.nl 2874 [2001:888:2000:d::a6]:57334 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:81442 --Apple-Mail=_425D012F-63AF-4AD3-B5F2-35BFC73C768E Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 How does the __del__ method have a reference to the module=E2=80=99s = globals dict? because it references the print function? Crazy. Is there any other way to comfort when a module is being deleted = beside defining a class object with a printing dtor? > On Nov 23, 2014, at 4:27 PM, Ian Kelly wrote: >=20 >=20 > On Nov 23, 2014 4:10 AM, "Patrick Stinson" > wrote: > > m =3D types.ModuleType('mine') > > exec(s, m.__dict__) > > print('deleting...') > > m =3D None > > print('done') > > > > and the output is: > > > > deleting... > > done > > __del__ > > > > I the =E2=80=9C__del__" to come between =E2=80=9Cdeleting=E2=80=A6=E2=80= =9D and =E2=80=9Cdone=E2=80=9D. This is not being run from the = interactive interpreter by via a .py file. >=20 > This suggests the presence of a reference cycle, since the object is = deleted afterward by the garbage collector. One cycle here is that the = __del__ function has a reference to the module's globals dict, which has = a reference to the class instance, which has a reference to the class, = which has a reference back to the function. There may be other cycles = here as well, but it may also be that the module object itself isn't = part of them. >=20 > --=20 > https://mail.python.org/mailman/listinfo/python-list --Apple-Mail=_425D012F-63AF-4AD3-B5F2-35BFC73C768E Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 How does the __del__ method have a reference to the = module=E2=80=99s globals dict? because it references the print = function?

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


On = Nov 23, 2014, at 4:27 PM, Ian Kelly <ian.g.kelly@gmail.com> wrote:


On Nov 23, 2014 4:10 AM, "Patrick Stinson" <patrickkidd@gmail.com> wrote:
> m =3D types.ModuleType('mine')
> exec(s, m.__dict__)
> print('deleting...')
> m =3D None
> print('done')
>
> and the output is:
>
> deleting...
> done
> __del__
>
> I the =E2=80=9C__del__" to come between =E2=80=9Cdeleting=E2=80=A6=E2= =80=9D and =E2=80=9Cdone=E2=80=9D. This is not being run from the = interactive interpreter by via a .py file.

This suggests the presence of a reference cycle, since the = object is deleted afterward by the garbage collector. One cycle here is = that the __del__ function has a reference to the module's globals dict, = which has a reference to the class instance, which has a reference to = the class, which has a reference back to the function. There may be = other cycles here as well, but it may also be that the module object = itself isn't part of them.

--
https://mail.python.org/mailman/listinfo/python-list

= --Apple-Mail=_425D012F-63AF-4AD3-B5F2-35BFC73C768E--