Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #22024
| Date | 2012-03-22 09:00 -0500 |
|---|---|
| From | Tycho Andersen <tycho@tycho.ws> |
| Subject | Re: Best way to disconnect from ldap? |
| References | (1 earlier) <CAMZYqRQR0VFweQgN8jb3wkx-opabvVQJy5zRtQQrv7tnnzivwA@mail.gmail.com> <CALvWhxvq-KO0ZxMwo-A7ieLyULHh95LAAiLon3zqBgMixZpFbA@mail.gmail.com> <4F6A4D02.6020403@tim.thechases.com> <20120322131447.GG19657@ccapuser-ubuntu.WICOURTS.GOV> <CAMZYqRRxtQD8g5GQOS1c_P_cFBC9sF1dp+qh1PNkBe0FX34FFw@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.889.1332424827.3037.python-list@python.org> (permalink) |
On Thu, Mar 22, 2012 at 06:27:45AM -0700, Chris Rebert wrote: > On Thu, Mar 22, 2012 at 6:14 AM, Tycho Andersen <tycho@tycho.ws> 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
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Best way to disconnect from ldap? John Gordon <gordon@panix.com> - 2012-03-21 19:30 +0000
Re: Best way to disconnect from ldap? "J. Cliff Dyer" <jcd@sdf.lonestar.org> - 2012-03-21 16:21 -0400
Re: Best way to disconnect from ldap? Chris Rebert <clp2@rebertia.com> - 2012-03-21 13:34 -0700
Re: Best way to disconnect from ldap? Chris Kaynor <ckaynor@zindagigames.com> - 2012-03-21 13:54 -0700
Re: Best way to disconnect from ldap? Tycho Andersen <tycho@tycho.ws> - 2012-03-22 08:14 -0500
Re: Best way to disconnect from ldap? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-03-22 17:26 +0000
Re: Best way to disconnect from ldap? Tim Chase <python.list@tim.thechases.com> - 2012-03-22 12:54 -0500
Re: Best way to disconnect from ldap? Terry Reedy <tjreedy@udel.edu> - 2012-03-22 15:27 -0400
Re: Best way to disconnect from ldap? Tycho Andersen <tycho@tycho.ws> - 2012-03-22 16:02 -0500
Re: Best way to disconnect from ldap? Chris Rebert <clp2@rebertia.com> - 2012-03-22 06:27 -0700
Re: Best way to disconnect from ldap? Tycho Andersen <tycho@tycho.ws> - 2012-03-22 09:00 -0500
Re: Best way to disconnect from ldap? John Gordon <gordon@panix.com> - 2012-04-05 18:38 +0000
Re: Best way to disconnect from ldap? Michael Ströder <michael@stroeder.com> - 2012-04-05 20:56 +0200
csiph-web