Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!newsfeed.eweka.nl!eweka.nl!feeder3.eweka.nl!newsfeed.xs4all.nl!newsfeed5.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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'cpython': 0.05; 'python': 0.08; '21,': 0.09; 'all?': 0.09; 'called.': 0.09; 'python-level': 0.09; 'sure,': 0.09; 'am,': 0.12; 'c++': 0.12; '__del__': 0.16; 'called,': 0.16; 'destructor': 0.16; 'scope,': 0.16; 'subject:ldap': 0.16; 'warn': 0.16; 'cc:addr:python-list': 0.16; 'wed,': 0.17; 'wrote:': 0.18; 'seems': 0.20; 'thus': 0.21; 'cc:no real name:2**0': 0.21; 'pointed': 0.21; 'received:209.85.210.174': 0.21; 'received:mail-iy0-f174.google.com': 0.21; 'header:In-Reply- To:1': 0.22; 'assume': 0.22; 'similarly': 0.23; 'though.': 0.23; 'fine': 0.24; '"this': 0.24; '(like': 0.26; 'guess': 0.26; 'classes': 0.26; 'stuff': 0.26; 'code': 0.26; 'beyond': 0.28; 'producing': 0.28; '(even': 0.29; 'received:gov': 0.29; 'cc:addr:python.org': 0.29; 'generally': 0.30; '22,': 0.30; 'behaves': 0.30; 'cycles': 0.30; 'chris': 0.30; 'subject:?': 0.31; 'thu,': 0.32; "i've": 0.32; 'does': 0.32; 'stopped': 0.32; 'typically': 0.32; 'idea': 0.32; 'changing': 0.32; 'there': 0.33; "can't": 0.33; 'header:User-Agent:1': 0.33; 'it?': 0.33; 'anything': 0.34; 'light': 0.35; 'something': 0.35; 'cc:2**1': 0.36; 'but': 0.37; 'reference': 0.37; 'received:google.com': 0.37; 'similar': 0.37; 'using': 0.37; 'received:209.85': 0.38; 'enough': 0.38; 'somewhat': 0.38; 'doing': 0.38; 'subject:from': 0.39; 'received:209': 0.39; 'more': 0.61; 'fact,': 0.63; 'ever': 0.64; 'guarantee': 0.66; 'gone': 0.68; 'anything.': 0.71; '-0500,': 0.84; 'bitten': 0.84; 'paranoia': 0.84; 'immediately,': 0.91; 'subject:Best': 0.93 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :in-reply-to:user-agent:x-gm-message-state:content-type :content-disposition:content-transfer-encoding; bh=cjzNxdS/O87KsEy9yWcNReEP4CcZq9czvsLF2eoS9aQ=; b=X3vDTwAalzX/fN6N6v07uAVsTlcajeDPVxwHYT/3+v+WLxoA3esqnuGKsYX/QQRbJq 814Va5IcMwKo1jmFqq2Pho3+rvmIEuf2PhC91ZyZttRx+YYB5x2sQAlJm5INMdbD4wup WZTdTL/it5m22Z3OV8b2KphHzjIvvb97ky+WBtiw+hDlVsWSzvPqH+sNYSXkX3s1stcf U1laHYw92GqC1U7H3Gwitydu2L2a+/7YD205tgB9wbD++VMNqIF4PdHGWTgaF7otr62W T1Iedtp50DI/60sJJ0vKoGqIiopLuI86WSlzlkDh9/BS+BjGlhfMjUxPXuuEPrr220O2 hogg== Date: Thu, 22 Mar 2012 09:00:50 -0500 From: Tycho Andersen To: Chris Rebert Subject: Re: Best way to disconnect from ldap? References: <4F6A4D02.6020403@tim.thechases.com> <20120322131447.GG19657@ccapuser-ubuntu.WICOURTS.GOV> MIME-Version: 1.0 In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-Gm-Message-State: ALoCoQkoIKX6hhB+7rZlsi5WV5IVmbKIxDn171VEmhWSkOTLRmo1Jo85fJSK2hTFge23ME7dkBfr Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 37 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1332424827 news.xs4all.nl 6885 [2001:888:2000:d::a6]:46233 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:22024 On Thu, Mar 22, 2012 at 06:27:45AM -0700, Chris Rebert wrote: > On Thu, Mar 22, 2012 at 6:14 AM, Tycho Andersen wrote: > > On Wed, Mar 21, 2012 at 04:49:54PM -0500, Tim Chase wrote: > >> On 03/21/12 15:54, Chris Kaynor wrote: > >> >As Chris Rebert pointed out, there is no guarantee as to when the > >> >__del__ method is called. CPython will generally call it immediately, > >> >however if there are reference cycles it may never call it > >> > >> And more maddeningly, modules/objects used/called from within the > >> __del__ may have already gone out of scope, producing > >> head-scratching errors.  I've been bitten by this enough times that > >> I just stopped using __del__ completely. > > > > I've had similar experiences. In fact, in light of all this - why does > > __del__ exist at all? Novice python users may (reasonably) assume it > > behaves similarly to a C++ destructor (even though the docs warn > > otherwise). > > > > Given that you can't trust __del__, is there a legitimate use case for > > it? > > Writing resource classes (like `file`) in C? Their __del__()s > typically involve little/less Python-level stuff and thus less > paranoia need be exercised. Sure, but you still have no guarantee that __del__ will ever be called, so it's a bad idea to rely on it to clean up anything. > There is somewhat of a perverse incentive in having such last-ditch > clean-up mechanisms though. "This code seems to work fine without > `with`, so why bother changing it?" Yeah, I guess I can see doing something like: __del__ = __exit__ but anything beyond that seems risky... \t