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
importlib.resources.as_file is leaving temporary file pointers open #100585
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. |


Bug report
importlib.resources.as_file is leaving temporary file pointers open after writing their contents
see
_write_contentsfunction in importlib/resources/_common.pyEasy to repeat, just run the test case below with
-WeLib.test.test_importlib.resources.test_resource.ResourceFromZipsTest01.test_as_file_directoryYour environment
I think it just needs to use
Path.write_bytesand keep the file pointer closed.Linked PRs
The text was updated successfully, but these errors were encountered: