Skip to content

Commit c625a77

Browse files
Copilotlostmsu
andcommitted
Fix resource leak: wrap p.exitcode assert in try/finally so p.close() always runs
Without try/finally, if `assert p.exitcode == 0` raises AssertionError, `p.close()` is never called. This leaves the Process object unclosed and causes `ResourceWarning: process ... not closed` on Python 3.12+. Co-authored-by: lostmsu <239520+lostmsu@users.noreply.github.com>
1 parent ae47f46 commit c625a77

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

tests/test_common.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,5 +155,7 @@ def run_in_subprocess(func, *args, **kwargs):
155155
p = get_context("spawn").Process(target=func, args=args, kwargs=kwargs)
156156
p.start()
157157
p.join()
158-
assert p.exitcode == 0, f"Subprocess {func.__name__!r} failed with exit code {p.exitcode}"
159-
p.close()
158+
try:
159+
assert p.exitcode == 0, f"Subprocess {func.__name__!r} failed with exit code {p.exitcode}"
160+
finally:
161+
p.close()

0 commit comments

Comments
 (0)