Replies: 1 comment
|
In pygit2 1.19.2, When the repository is actually deallocated, pygit2 calls For deterministic cleanup before repo = pygit2.Repository(repo_path)
branch = walker = commit = None
try:
branch = repo.branches["main"]
walker = repo.walk(branch.target)
for commit in walker:
# Process the commit without retaining it past cleanup.
pass
finally:
# Also clear containers that retain commits or other pygit2 objects.
commit = None
walker = None
branch = None
repo.free()
repo = None
shutil.rmtree(repo_path, onexc=remove_readonly)The ordering matters: a libgit2 revwalker owns an additional ODB reference, so calling |
Uh oh!
There was an error while loading. Please reload this page.
Environment:
Minimal example:
RepoWalkerFileHandles.py
Required changes to run: Change repo_path to any directory with a git repository.
Explanation:
Opening a repository with pygit2.Repository and using a commit walker with repo.walk seems to keep the file handles over some .pack files in the repository. When I attempt to delete the repository afterwards with shutil.rmtree, I get an WinError 32 stating that the .pack files are blocked by another process. These file handles are not removed when deleting the pygit2.Repository object or the walker object. They can only be removed by explicitly calling Repository.free() or gc.collect().
Question:
Is this expected behavior, or should pygit2.Repository release these handles automatically when the Repository object is destroyed?
All reactions