-
-
Notifications
You must be signed in to change notification settings - Fork 32k
importlib.resources.as_file is leaving temporary file pointers open #100585
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
Comments
Just from a quick glance, I think you're right in that the code is relying on implicit GC to close the file, which generally isn't good practice. @jaraco to chime in. What I don't remember is whether its |
This issue is fixed in python/importlib_resources#274, which just hasn't been merged into CPython yet. All skeleton-based projects (including importlib_metadata) now enable ResourceWarnings so these kinds of issues will get caught early. In that fix, a context manager was used instead of relying on |
Yes I just saw the context manager fix, that's also addressing the issue indeed. I also like one line approach more, I find using |
I cherry-picked the change into importlib_resources as python/importlib_resources@d623078. Thanks for reporting and the fix. |
Uh oh!
There was an error while loading. Please reload this page.
Bug report
importlib.resources.as_file is leaving temporary file pointers open after writing their contents
see
_write_contents
function in importlib/resources/_common.pyEasy to repeat, just run the test case below with
-We
Lib.test.test_importlib.resources.test_resource.ResourceFromZipsTest01.test_as_file_directory
Your environment
I think it just needs to use
Path.write_bytes
and keep the file pointer closed.Linked PRs
The text was updated successfully, but these errors were encountered: