New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-93353: Fix importlib.resources._tempfile() finalizer #93377
Conversation
I convert the PR to a draft, it lacks an unit test. I plan to write a test.support helper function to make sure that an object is destroyed as late as possible during Python finalization. The first implementation would use os.register_at_fork(). But I also would like to change when os.register_at_fork() is cleared. IMO it's cleared too late, causing bugs like #93353 which are very hard to debug since Python cannot log errors anymore. Too many things are cleared/finalized to be able to log an error at this point. The point of the helper is to find a new hook if os.register_at_fork() is cleared earlier ;-) Also, I'm writing in a train and I'm close to the train station, so I will finish later :-D |
Until I write an automated test, you can test the fix manually: #93353 (comment) |
Fix the importlib.resources.as_file() context manager to remove the temporary file if destroyed late during Python finalization: keep a local reference to the os.remove() function. Patch by Victor Stinner.
I rebased my PR, removed debug logs, and I marked the added parameter as keyword-only. |
LGTM, great debugging :D |
Thanks @vstinner for the PR |
Thanks @vstinner for the PR |
…GH-93377) Fix the importlib.resources.as_file() context manager to remove the temporary file if destroyed late during Python finalization: keep a local reference to the os.remove() function. Patch by Victor Stinner. (cherry picked from commit 443ca73) Co-authored-by: Victor Stinner <vstinner@python.org>
GH-93780 is a backport of this pull request to the 3.10 branch. |
…GH-93377) Fix the importlib.resources.as_file() context manager to remove the temporary file if destroyed late during Python finalization: keep a local reference to the os.remove() function. Patch by Victor Stinner. (cherry picked from commit 443ca73) Co-authored-by: Victor Stinner <vstinner@python.org>
GH-93781 is a backport of this pull request to the 3.11 branch. |
Fix the importlib.resources.as_file() context manager to remove the temporary file if destroyed late during Python finalization: keep a local reference to the os.remove() function. Patch by Victor Stinner. (cherry picked from commit 443ca73) Co-authored-by: Victor Stinner <vstinner@python.org>
Fix the importlib.resources.as_file() context manager to remove the temporary file if destroyed late during Python finalization: keep a local reference to the os.remove() function. Patch by Victor Stinner. (cherry picked from commit 443ca73) Co-authored-by: Victor Stinner <vstinner@python.org>
My PR #93776 should detect such bug, to make the debug way more straightforward ;-) |
This probably needs to be ported to importlib_resources. |
Fix the importlib.resources.as_file() context manager to remove the
temporary file if destroyed late during Python finalization: keep a
local reference to the os.remove() function. Patch by Victor Stinner.