Skip to content

ResourceWarning (python 3) #263

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

Closed
ryneeverett opened this issue Feb 22, 2015 · 2 comments
Closed

ResourceWarning (python 3) #263

ryneeverett opened this issue Feb 22, 2015 · 2 comments
Assignees

Comments

@ryneeverett
Copy link

Every time I add a file to the index I get the following warning:

home/ryne/projects/GitPython/git/index/base.py:609: ResourceWarning: unclosed file <_io.BufferedReader name='my_file.txt'>

This warning was added in python 3.2 and is triggered by allowing the reference count of an opened file to go to zero -- in this case stream in IndexFile._store_path.

Is it safe to call stream.close() after the istream object is created?

@Byron
Copy link
Member

Byron commented Feb 23, 2015

Sorry for the late reply.
The IndexFile implementation doesn't take ownership if the passed-in streams, and therefore just expects them to be readable until EOF.
There is not a single close call on streams in the implementation.

To answer your question: Yes, it should be safe to close your own streams, and it's even recommended to prevent leakage.

However, your question raises my fear that in python 3, resource handling won't work anymore. Usually you could assume that file handles/streams are closed when they are dropped, but as __del__() now only gets called sometime, calls to add() could cause exceeding the maximum amount of concurrently open files of the python process.

@Byron Byron added this to the v0.3.7 - Fixes milestone Feb 23, 2015
@Byron Byron self-assigned this Apr 8, 2015
@Byron Byron closed this as completed in 98f6995 Apr 8, 2015
@Byron
Copy link
Member

Byron commented Apr 8, 2015

You can watch the development stream on youtube.

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

No branches or pull requests

2 participants