[issue42248] Raised exception in Enum keeping user objects alive unnecessarily

Eric Froemling report at bugs.python.org
Mon Nov 2 15:46:49 EST 2020


New submission from Eric Froemling <ericfroemling at gmail.com>:

I've run into an issue where exceptions thrown by Enum constructors are keeping my objects alive. The underlying issue seems to be the same as https://bugs.python.org/issue36820

The same method used to fix the issue above seems to work here: simply adding a try/finally clause around the error handling at the end of enum.Enum.__new__() which sets ve_exc and exc to None does the trick.

I've attached a short script which demonstrates the issue. I realize that the cyclic garbage collector will eventually handle this case, but its a bummer to lose determinism in the destruction of my objects.

I'd be happy to create a PR for this or whatever I can do to help; just let me know if I should (I'm new here).

----------
components: Library (Lib)
files: enum_ref_loop_example.py
messages: 380249
nosy: efroemling
priority: normal
severity: normal
status: open
title: Raised exception in Enum keeping user objects alive unnecessarily
versions: Python 3.8
Added file: https://bugs.python.org/file49564/enum_ref_loop_example.py

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42248>
_______________________________________


More information about the Python-bugs-list mailing list