Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3a.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.009 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'interpreter': 0.05; 'output': 0.05; 'class,': 0.07; 'subject:module': 0.09; '.py': 0.16; '23,': 0.16; '__del__': 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; 'instance,': 0.24; 'file.': 0.24; '>': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; 'subject:skip:i 10': 0.31; 'class': 0.32; 'run': 0.32; 'subject:with': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'done': 0.36; 'being': 0.38; 'skip:& 10': 0.38; 'nov': 0.38; 'to:addr:python-list': 0.38; 'itself': 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'back': 0.62; 'skip:\xe2 10': 0.65; 'here': 0.66; 'between': 0.67; 'dict,': 0.84 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:to :content-type; bh=pngI6Z9fSWDc8WYOdh5UQikmtY9s1MT7y/cSBHP5J80=; b=SnC+GEYa22vEryyb8Z0AIKwxdtcVqA4bHkzvK32OjHW+R/pNOFz9rtsxsIqq3kUizS JgYhxOj7aE6dBQAnjl8IjZ45rpZ9k7DlA7ZTQ+V6JUjPAyGE0i7fECqNGW9Y2ow0ZQo7 wmRbkoRFwrdgpaXv6X0iHCxWa0Pp4vmmo2c74/5J1bmcepK3CodmODRNBHAA3l2zus+g sfh/wUDw1p80pKY5T6ippDXEVR2TdwjABs6KYiSrquZQPpKS8ZGfdWPlsffwPpDjTAO3 T+yCHZqK8t08EVN5LvtHWW1AcRC/xSJ7qrIL81TuJd4XkFMIREd7cFt/jKutNCRfyeee sHcA== MIME-Version: 1.0 X-Received: by 10.68.111.161 with SMTP id ij1mr28369730pbb.10.1416792434858; Sun, 23 Nov 2014 17:27:14 -0800 (PST) In-Reply-To: References: Date: Sun, 23 Nov 2014 18:27:14 -0700 Subject: Re: unloading a module created with imp.new_module From: Ian Kelly To: Python Content-Type: multipart/alternative; boundary=047d7b5db7facce0ae050890b1be 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: 59 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1416792444 news.xs4all.nl 2924 [2001:888:2000:d::a6]:50457 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:81412 --047d7b5db7facce0ae050890b1be Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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. 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. --047d7b5db7facce0ae050890b1be Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable


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 int= eractive interpreter by via a .py file.

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

--047d7b5db7facce0ae050890b1be--