Repository navigation
🐛 fix(api): keep __del__ off module globals at shutdown - #933
Open
kushaldave002 wants to merge 1 commit into
Open
kushaldave002 wants to merge 1 commit into
kushaldave002 wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
BaseFileLock.__del__calledos.getpid()andsys.is_finalizing()through module globals. When CPython finalizes a dropped lock during interpreter shutdown, module teardown may already have set those globals toNone. The finalizer then raisesAttributeError: 'NoneType' object has no attribute 'getpid', and CPython prints it as an ignored exception on every exit.The fix binds both callables as default arguments when the function is defined, the same way the standard library does in
subprocess.Popen.__del__. Everything after these two checks already runs insidecontextlib.suppress(Exception).The new test
test_del_survives_module_teardowncoversFileLockandSoftFileLock. It patchesfilelock._api.osandfilelock._api.systoNoneto imitate teardown, then calls__del__directly, as the other finalizer tests do. It fails onmainwith the traceback from the issue and passes with the fix.A
bugfixchangelog fragment is included.How I tested it (Python 3.12, local venv):
pytest -n auto tests --no-cov: 2908 passed, 134 skipped.pre-commit run --files <changed files>: ruff-check, simplint, ruff-format and flake8-lazy all pass.ty check --python .venv --output-format concise --error-on-warning .: all checks passed.Fixes #932