From 1dcbbc47bf458fa100769e50240de2d2bfaf388f 2022-08-30 09:51:23
From: Jacob Hall <jwhall@email.wm.edu>
Date: 2022-08-30 09:51:23
Subject: [PATCH] terminal interface: catch exception when standard stream is closed

if a standard stream is closed, e.g. `import sys;
sys.stdin.close()`, a ValueError is raised when the stream is read.
this commit adds a try .. except statement to catch that exception
in IPython/terminal/interactiveshell.py

---

diff --git a/IPython/terminal/interactiveshell.py b/IPython/terminal/interactiveshell.py
index 06724be..b7739c8 100644
--- a/IPython/terminal/interactiveshell.py
+++ b/IPython/terminal/interactiveshell.py
@@ -91,7 +91,12 @@ def get_default_editor():
 # - no isatty method
 for _name in ('stdin', 'stdout', 'stderr'):
     _stream = getattr(sys, _name)
-    if not _stream or not hasattr(_stream, 'isatty') or not _stream.isatty():
+    try:
+        if not _stream or not hasattr(_stream, "isatty") or not _stream.isatty():
+            _is_tty = False
+            break
+    except ValueError:
+        # stream is closed
         _is_tty = False
         break
 else: