Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 862543a

Browse files
committed
Don't close sys.stdin with quit() if sys.stdin wraps fd 0. Otherwise it will raise a warning: Lib/io.py:1221: RuntimeWarning: Trying to close unclosable fd
1 parent c90584e commit 862543a

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

Lib/site.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,12 @@ def __call__(self, code=None):
247247
# Shells like IDLE catch the SystemExit, but listen when their
248248
# stdin wrapper is closed.
249249
try:
250-
sys.stdin.close()
250+
fd = -1
251+
if hasattr(sys.stdin, "fileno"):
252+
fd = sys.stdin.fileno()
253+
if fd != 0:
254+
# Don't close stdin if it wraps fd 0
255+
sys.stdin.close()
251256
except:
252257
pass
253258
raise SystemExit(code)

0 commit comments

Comments
 (0)