Skip to content

Fix nostdout() to restore sys.stdout after exceptions#558

Merged
wasserth merged 1 commit intowasserth:masterfrom
mhalle:fix/nostdout-exception-safety
Mar 30, 2026
Merged

Fix nostdout() to restore sys.stdout after exceptions#558
wasserth merged 1 commit intowasserth:masterfrom
mhalle:fix/nostdout-exception-safety

Conversation

@mhalle
Copy link
Copy Markdown
Contributor

@mhalle mhalle commented Mar 24, 2026

Summary

  • nostdout() context manager replaced sys.stdout with a DummyFile but only restored it on normal exit. If an exception was raised during the yield (e.g., a failing nnU-Net prediction), sys.stdout remained permanently suppressed for the rest of the process.
  • This is used around inference calls in nnunet.py (lines 565 and 592), so a prediction failure could leave the process mute — no further print() output would be visible.
  • Fix: wrap the yield in try/finally to guarantee sys.stdout is restored.

Test plan

  • Trigger a prediction error within a nostdout() block and verify that subsequent print() calls produce output
  • Verify normal (non-error) prediction still suppresses stdout as intended

nostdout() replaced sys.stdout with a DummyFile but only restored it
on normal exit. If an exception occurred during the yield (e.g., a
failing nnU-Net prediction), sys.stdout remained suppressed for the
rest of the process. Use try/finally to guarantee restoration.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@wasserth wasserth merged commit b32a351 into wasserth:master Mar 30, 2026
@mhalle mhalle deleted the fix/nostdout-exception-safety branch April 3, 2026 00:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants