Skip to content

Commit

Permalink
fix: protect stdout/stderr restoration in `InProcessKernel._redirecte…
Browse files Browse the repository at this point in the history
…d_io` (#1122)
  • Loading branch information
charles-cooper authored Jun 8, 2023
1 parent 3455c29 commit 1c7f626
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions ipykernel/inprocess/ipkernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,11 @@ def _input_request(self, prompt, ident, parent, password=False):
def _redirected_io(self):
"""Temporarily redirect IO to the kernel."""
sys_stdout, sys_stderr = sys.stdout, sys.stderr
sys.stdout, sys.stderr = self.stdout, self.stderr
yield
sys.stdout, sys.stderr = sys_stdout, sys_stderr
try:
sys.stdout, sys.stderr = self.stdout, self.stderr
yield
finally:
sys.stdout, sys.stderr = sys_stdout, sys_stderr

# ------ Trait change handlers --------------------------------------------

Expand Down

0 comments on commit 1c7f626

Please sign in to comment.