does python have useless destructors?

David Turner dkturner at telkomsa.net
Sat Jun 12 06:32:19 EDT 2004


Hi

Roy Smith <roy at panix.com> wrote in message news:<roy-708E10.17573911062004 at reader2.panix.com>...
> 
> Now, I've designed Top to be a sort of bastard cousin (or maybe an evil 
> twin?) of a singleton.  Instead of getting the same one each time, you 
> get a new one but you're only allowed to create one of them at a time.  
> The exclusiveAccessResource might be something like a mutex, or it might 
> be something external like a low-numbered network port.  If the "del 
> Top" doesn't actually free the resource, the second call to Top() will 
> fail.

I'm not sure that this is relevant.  You know that Top is not a
deterministic object; therefore you know you can't be sure when it (or
anything it owns) should be destroyed.  What you *do* know is that it
will take its Bottom along with it when it goes.  That's the invariant
we're trying to establish here.

Generally one addresses the problem of the resource-safety of a class
when one is designing it.  Top is not resource-safe, and that's a
problem that can't (and shouldn't) be addressed post-hoc.

Regards
David Turner



More information about the Python-list mailing list