This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author tim.peters
Recipients a-feld, deekay, pablogsal, tim.peters
Date 2020-04-20.16:32:36
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1587400356.26.0.685373569009.issue40312@roundup.psfhosted.org>
In-reply-to
Content
Allan, we don't (at least not knowingly) write tests that rely on order of end-of-life actions, because the _language_ defines nothing about the order.  So you can permute the order and it's unlikely any standard tests would fail.

The only reason your example "works" outside of cyclic gc is because, as already noted, CPython (the implementation you're using, not Python the language) primarily relies on reference counting.  That guarantees __del__ is called first, but that's not a language guarantee, it's a consequence of reference counting invoking __del__ IMMEDIATELY upon the refcount falling to 0.  The _language_ not only doesn't guarantee that, it doesn't even guarantee that __del__ will ever be called.

For CPython (this implementation), it's important that we don't introduce gratuitous breakage of programs that are "working" because of implementation details.  How do you know that no program currently relies on the implementation detail that cyclic gc happens to run callbacks before finalizers now?  CPython has done that for many years, and I personally wouldn't risk breaking "working" programs by flipping that order now, not without truly compelling reason (example: stopping a segfault would be compelling).

Pablo, as above, I'm inclined to leave things alone unless we can "prove" no current code could possibly be relying (even by accident) on that gc currently runs callbacks before finalizers.  Which may be the case!  I don't know ;-)
History
Date User Action Args
2020-04-20 16:32:36tim.peterssetrecipients: + tim.peters, pablogsal, a-feld, deekay
2020-04-20 16:32:36tim.peterssetmessageid: <1587400356.26.0.685373569009.issue40312@roundup.psfhosted.org>
2020-04-20 16:32:36tim.peterslinkissue40312 messages
2020-04-20 16:32:36tim.peterscreate