RFC: Proposal: Deterministic Object Destruction

bartc bc at freeuk.com
Sun Mar 4 14:02:29 EST 2018


On 04/03/2018 14:11, Ooomzay wrote:

> Well I see a lot of posts that indicate peeps here are more comfortable with
> the "with" idiom than the RAII idiom but I have not yet seen a single
> linguistic problem or breakage.
> 
> As it happens I have used RAII extensively with CPython to manage a debugging environment with complex external resources that need managing very efficiently.

I have bit of problem with features normally used for the housekeeping 
of a language's data structures being roped in to control external 
resources that it knows nothing about.

Which also means that if X is a variable with the sole reference to some 
external resource, then a mere:

    X = 0

will close, destroy, or discard that resource. If the resource is 
non-trivial, then it perhaps deserves a non-trivial piece of code to 
deal with it when it's no longer needed.

It further means that when you did want to discard an expensive 
resource, then X going out of scope, calling del X or whatever, will not 
work if a copy of X still exists somewhere.

-- 
bartc



More information about the Python-list mailing list