-
-
Notifications
You must be signed in to change notification settings - Fork 34.8k
atexit module breaks refleak check #139289
Copy link
Copy link
Open
Labels
extension-modulesC modules in the Modules dirC modules in the Modules dirtestsTests in the Lib/test dirTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Metadata
Metadata
Assignees
Labels
extension-modulesC modules in the Modules dirC modules in the Modules dirtestsTests in the Lib/test dirTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Fields
Give feedbackNo fields configured for issues without a type.
Bug report
Bug description:
If the test registers a callback with
atexitmodule, refleak test will consider it a leak.This is the root cause of the buildbot failure of #139185. It's a couple of coincidences that caused the seemingly unrelated issue. Basically, clearing the module cache in
test_zipimportmade the module-level code inrlcompleter, which includes a register toatexit, run more than once.There are a few possible approaches to fix this, but I did not find the solution that I'm immediately happy with.
I consider this a test framework bug as this should be a valid behavior. The ideal solution is to keep the
atexitcallbacks before running test in a loop and restore it after. However,atexitdoes not provide such an interface, public or private. You can either clear it or run it. The callbacks are stored in a state of the interpreter and we don't have any access to it.Without that, we either need to somehow calculate the allocated memory by
atexit, or hope that no one writes a test that writes toatexit. Of course there might be other ways that I did not think of.CPython versions tested on:
CPython main branch
Operating systems tested on:
macOS
Linked PRs