Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3e829eb

Browse filesBrowse files
committed
util: close lockfile after opening successfully
Otherwise, this will leak file handles and can be a problem in Windows. Also, `closefd=true` is the default here, so need to pass it explicitly. Regression from #1619. I noticed after [our tests started raising `ResourceWarning`][1]. ```python Traceback (most recent call last): File "/opt/hostedtoolcache/Python/3.8.17/x64/lib/python3.8/site-packages/git/util.py", line 938, in _obtain_lock_or_raise open(lock_file, mode='w', closefd=True) ResourceWarning: unclosed file <_io.TextIOWrapper name='/tmp/pytest-of-runner/pytest-0/popen-gw0/external0/project.git/.git/config.lock' mode='w' encoding='UTF-8'> ``` [1]: https://github.com/iterative/dvc/actions/runs/6055520480/job/16434544764#step:6:869
1 parent f882cd8 commit 3e829eb
Copy full SHA for 3e829eb

File tree

1 file changed

+2
-1
lines changed
Filter options

1 file changed

+2
-1
lines changed

‎git/util.py

Copy file name to clipboardExpand all lines: git/util.py
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,8 @@ def _obtain_lock_or_raise(self) -> None:
935935
)
936936

937937
try:
938-
open(lock_file, mode='w', closefd=True)
938+
with open(lock_file, mode='w'):
939+
pass
939940
except OSError as e:
940941
raise IOError(str(e)) from e
941942

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.