Skip to content

Random git.repo.base.Repo.__del__ exceptions #610

Closed
@xsteve

Description

@xsteve

When an exception is thrown the cleanup of Repo objects causes some very strange back traces.
When I run my test script several times. I have different results. Sometimes it works.
On other runs I have either the errors a), b) or c)

/work/GitPython/git/repo/base.py

def __del__(self):
    self.close()                  # line 189

def close(self):
    if self.git:
        self.git.clear_cache()
        gc.collect()              # line 194
        gitdb.util.mman.collect() # line 195
        gc.collect()

a)

Exception ignored in: <bound method GitRepository.__del__ of <GitRepository '/big/yocto/msc-ldk'>>
Traceback (most recent call last):
  File "/work/GitPython/git/repo/base.py", line 189, in __del__
  File "/work/GitPython/git/repo/base.py", line 195, in close
AttributeError: 'NoneType' object has no attribute 'mman'

b)

Exception ignored in: <bound method GitRepository.__del__ of <GitRepository '/big/yocto/msc-ldk'>>
Traceback (most recent call last):
  File "/work/GitPython/git/repo/base.py", line 189, in __del__
  File "/work/GitPython/git/repo/base.py", line 194, in close
TypeError: 'NoneType' object is not callable

c)

Exception ignored in: <bound method GitRepository.__del__ of <GitRepository '/big/yocto/msc-ldk'>>
Traceback (most recent call last):
  File "/work/GitPython/git/repo/base.py", line 189, in __del__
  File "/work/GitPython/git/repo/base.py", line 194, in close
AttributeError: 'NoneType' object has no attribute 'collect'

One solution to get rid of the back traces is to wrap the self.close() call in a try-except handler:

def __del__(self):
    try:
        self.close()
    except:
        pass

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions