Skip to content

Commit 4d43e6b

Browse files
committed
add pablo's suggestions
1 parent f970118 commit 4d43e6b

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

Lib/profiling/sampling/cli.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,13 +1111,14 @@ def _handle_live_run(args):
11111111
process.wait()
11121112
# Read any stderr output (tracebacks, errors, etc.)
11131113
if process.stderr:
1114-
try:
1115-
stderr = process.stderr.read()
1116-
if stderr:
1117-
print(stderr.decode(), file=sys.stderr)
1118-
except (OSError, ValueError):
1119-
# Ignore errors if pipe is already closed
1120-
pass
1114+
with process.stderr:
1115+
try:
1116+
stderr = process.stderr.read()
1117+
if stderr:
1118+
print(stderr.decode(), file=sys.stderr)
1119+
except (OSError, ValueError):
1120+
# Ignore errors if pipe is already closed
1121+
pass
11211122

11221123

11231124
def _handle_replay(args):

Lib/test/test_profiling/test_sampling_profiler/test_live_collector_ui.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ def mock_init_curses_side_effect(self, n_times, mock_self, stdscr):
839839
mock_self.display.simulate_input(ord('q'))
840840

841841
def test_run_failed_module_live(self):
842-
"""Test that running a existing module that fails exists with clean error."""
842+
"""Test that running a existing module that fails exits with clean error."""
843843

844844
args = [
845845
"profiling.sampling.cli", "run", "--live", "-m", "test",
@@ -886,10 +886,7 @@ def test_run_failed_script_live(self):
886886
self.assertIn(
887887
'sample(s) collected (minimum 200 required for TUI)', stderr
888888
)
889-
self.assertEndsWith(
890-
stderr,
891-
'ZeroDivisionError: division by zero\n\n'
892-
)
889+
self.assertIn('ZeroDivisionError', stderr)
893890

894891

895892
if __name__ == "__main__":

0 commit comments

Comments
 (0)