[Python-Dev] PEP 442 accepted (original) (raw)
Nick Coghlan ncoghlan at gmail.com
Sat Jun 15 06:57:49 CEST 2013
- Previous message: [Python-Dev] PEP 442 accepted
- Next message: [Python-Dev] PEP 442 accepted
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 15 June 2013 03:34, Antoine Pitrou <solipsis at pitrou.net> wrote:
On Wed, 5 Jun 2013 09:10:54 -0700 Benjamin Peterson <benjamin at python.org> wrote:
I (and Guido) are accepting PEP 442 (Safe object finalization) on the condition that finalizers are only ever called once globally. Ok, so there's an issue with that condition: it can't be upholded on non-GC objects. Creating a non-GC object is quite obscure and rare, though, since it requires basically a class with no dict and an empty slots: class C: slots = () survivors = [] def del(self): self.survivors.append(self)
In this case, a C instance's del will be called every time destruction is attempted, not only once. Is that a realistic problem?
So, to trigger that del() method a second time, such an object would have to be:
- Defined in the first place (the use cases for stateless objects with destructors seem rare...)
- Hanging off a reference cycle
- Which then gets resurrected
If it isn't easy to fix by changing the way such classes are constructed by typeobject.c (i.e. force them to be GC-aware when they define a del method, since they may still be hanging off the edge of a reference cycle, even if they can't form one themselves), I'd say chalk it up as a CPython wart and not worry about it for now.
As far as the test_subtype_resurrection failure goes, I think the associated comment says it all: "(On non-CPython implementations, however, del is typically not called again.)"
The test should just be rewritten to check that del is only called once in the face of resurrection.
Cheers, Nick.
-- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
- Previous message: [Python-Dev] PEP 442 accepted
- Next message: [Python-Dev] PEP 442 accepted
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]