Skip to content

Commit fc90aa0

Browse files
committed
dev(hansbug): make sure output capture can normally quit on any cases
1 parent cdb8013 commit fc90aa0

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

hbutils/testing/capture/output.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,18 @@ def _capture_via_tempfile() -> ContextManager[OutputCaptureResult]:
127127
with redirect_stdout(f_stdout), redirect_stderr(f_stderr):
128128
yield r
129129
finally:
130-
r.put_result(
131-
pathlib.Path(stdout_file).read_text(encoding='utf-8'),
132-
pathlib.Path(stderr_file).read_text(encoding='utf-8'),
133-
)
130+
if not f_stdout.closed:
131+
f_stdout.close()
132+
if not f_stderr.closed:
133+
f_stderr.close()
134+
try:
135+
r.put_result(
136+
pathlib.Path(stdout_file).read_text(encoding='utf-8'),
137+
pathlib.Path(stderr_file).read_text(encoding='utf-8'),
138+
)
139+
except: # process for extreme cases to avoid lock stuck
140+
r.put_result(None, None)
141+
raise
134142

135143

136144
@contextmanager

0 commit comments

Comments
 (0)