Skip to content
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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented May 31, 2022

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.

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.
@vstinner
Copy link
Member Author

@vstinner vstinner commented May 31, 2022

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

@vstinner
Copy link
Member Author

@vstinner vstinner commented May 31, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants