Skip to content

Commit 203ee2b

Browse files
authored
Fix Exception in OutStream.close() (#1076)
This bug fixes an Exception which was thrown in OutStream.close() whenever the OutStream was constructed with watchfd=False. A regression test was also added to test_io.py. Co-authored-by: Ilya Sherstyuk <isherstyuk@nvidia.com>
1 parent b4ea598 commit 203ee2b

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

ipykernel/iostream.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ def __init__(
401401
self._buffer = StringIO()
402402
self.echo = None
403403
self._isatty = bool(isatty)
404+
self._should_watch = False
404405

405406
if (
406407
watchfd
@@ -449,7 +450,7 @@ def set_parent(self, parent):
449450

450451
def close(self):
451452
"""Close the stream."""
452-
if sys.platform.startswith("linux") or sys.platform.startswith("darwin"):
453+
if self._should_watch:
453454
self._should_watch = False
454455
self.watch_fd_thread.join()
455456
if self._exc:

ipykernel/tests/test_io.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ def test_outstream():
9898
stream = OutStream(session, pub, "stdout")
9999
stream = OutStream(session, thread, "stdout", pipe=object())
100100

101+
stream = OutStream(session, thread, "stdout", watchfd=False)
102+
stream.close()
103+
101104
stream = OutStream(session, thread, "stdout", isatty=True, echo=io.StringIO())
102105
with pytest.raises(io.UnsupportedOperation):
103106
stream.fileno()

0 commit comments

Comments
 (0)