Skip to content

ResourceWarning (python 3) #263

Description

@ryneeverett

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?

Activity

  1. Byron commented on Feb 23, 2015

    @Byron
    Member

    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.

  2. added this to the v0.3.7 - Fixes milestone on Feb 23, 2015
  3. self-assigned this
    on Apr 8, 2015
  4. Byron commented on Apr 8, 2015

    @Byron
    Member

    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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions