[Python-Dev] PEP 442 clarification for type hierarchies (original) (raw)

Antoine Pitrou solipsis at pitrou.net
Tue Aug 6 19:29:42 CEST 2013


On Tue, 06 Aug 2013 18:38:51 +0200 Stefan Behnel <stefan_ml at behnel.de> wrote:

Antoine Pitrou, 06.08.2013 17:49: > Le Tue, 06 Aug 2013 17🔞59 +0200, > Stefan Behnel a écrit : >> If a Python class with a >> del inherits from an extension type that implements >> tpfinalize(), then whose tpfinalize() will be executed first? > > Then only the Python del gets called. It should call > super().del() manually, to ensure the extension type's > tpfinalize gets called.

Ok, but then all I have to do in order to disable C level finalisation for a type is to inherit from it and provide an empty del method. I think that disqualifies the feature for the use in Cython. Finalisation at the Python level is nice, but at the C level it's usually vital. I had originally read this PEP as a way to get better guarantees than what dealloc can provide, but your above statement makes it rather the opposite.

Anything vital should probably be ensured by tp_dealloc. For example, you might close an fd early in tp_finalize, but also ensure it gets closed in tp_dealloc in the case tp_finalize wasn't called.

(that said, you can also have fd leaks in pure Python...)

Regards

Antoine.



More information about the Python-Dev mailing list