Skip to content

Commit 2aee615

Browse files
Fix popen cleanup in git file finder to prevent gc errors
- Add proper proc.wait() call in finally block to ensure process is reaped - Add timeout and fallback to proc.kill() to prevent hanging - This should resolve gc errors with popen objects in test_case_cwd_evil[git] on Windows The previous code only called proc.wait() in the exception handler, leaving processes unreleased in the normal flow, which could cause gc warnings about unclosed subprocess popen objects.
1 parent 6fb72b7 commit 2aee615

File tree

1 file changed

+9
-1
lines changed
  • src/setuptools_scm/_file_finders

1 file changed

+9
-1
lines changed

src/setuptools_scm/_file_finders/git.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,16 @@ def _git_ls_files_and_dirs(toplevel: str) -> tuple[set[str], set[str]]:
8484
# ensure we avoid resource warnings by cleaning up the process
8585
proc.stdout.close()
8686
proc.terminate()
87+
# Wait for process to actually terminate and be reaped
88+
try:
89+
proc.wait(timeout=5) # Add timeout to avoid hanging
90+
except subprocess.TimeoutExpired:
91+
log.warning("git archive process did not terminate gracefully, killing")
92+
proc.kill()
93+
proc.wait()
8794
except Exception:
88-
if proc.wait() != 0:
95+
# proc.wait() already called in finally block, check if it failed
96+
if proc.returncode != 0:
8997
log.error("listing git files failed - pretending there aren't any")
9098
return set(), set()
9199

0 commit comments

Comments
 (0)