[Python-Dev] Deletion order when leaving a scope?
Michael Hudson
mwh at python.net
Fri Jan 19 20:28:16 CET 2007
Nick Coghlan <ncoghlan at gmail.com> writes:
> Neil Toronto wrote:
>> I imagine this would be important to someone expecting system resources
>> to be cleaned up, closed, deallocated, or returned inside of __del__
>> methods. Someone coming from C++ might expect LIFO behavior because
>> common idioms like RAII (Resource Allocation Is Instantiation) don't
>> work otherwise. A Java programmer wouldn't care, being used to cleaning
>> up resources manually with a try...catch...finally.
>>
>> I'm just putting a possible motivation on the concern. It happens that
>> the Pythonic Way is also the Java Way in this area: don't expect any
>> specific deletion order (don't even expect a guaranteed call to
>> __del__), and manually clean up after yourself. As a warning, this has
>> been the subject of a great many flame wars between C++ and Java
>> programmers...
>
> We know. Python 2.5 added a new statement (with) and a new standard
> library module (contextlib) to allow resource deallocation to be dealt
> with cleanly without requiring assumptions about the interpreter's
> memory model.
>
> While RAII isn't mentioned explicitly in the corresponding PEP (PEP
> 343), it was certainly a factor in the python-dev discussions.
It's mentioned in PEP 310, the predecessor to PEP 343.
Cheers,
mwh
--
"I lacked the courage to investigate the weaknesses of the wicked,
because I discovered they are the same as the weaknesses of the
saintly." -- The Name Of The Rose, Umberto Eco
More information about the Python-Dev
mailing list