[Python-Dev] Deletion order when leaving a scope?

Nick Coghlan ncoghlan at gmail.com
Fri Jan 19 14:20:55 CET 2007


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.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://www.boredomandlaziness.org


More information about the Python-Dev mailing list