Closed
Description
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?
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
Relationships
Development
No branches or pull requests
Activity
Byron commentedon 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 toadd()
could cause exceeding the maximum amount of concurrently open files of the python process.Byron commentedon Apr 8, 2015
You can watch the development stream on youtube.