mirror of
https://github.com/python/cpython.git
synced 2025-10-13 02:13:03 +00:00
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
This commit is contained in:
parent
c90584ecc1
commit
862543aa85
1 changed files with 6 additions and 1 deletions
|
@ -247,7 +247,12 @@ def setquit():
|
||||||
# Shells like IDLE catch the SystemExit, but listen when their
|
# Shells like IDLE catch the SystemExit, but listen when their
|
||||||
# stdin wrapper is closed.
|
# stdin wrapper is closed.
|
||||||
try:
|
try:
|
||||||
sys.stdin.close()
|
fd = -1
|
||||||
|
if hasattr(sys.stdin, "fileno"):
|
||||||
|
fd = sys.stdin.fileno()
|
||||||
|
if fd != 0:
|
||||||
|
# Don't close stdin if it wraps fd 0
|
||||||
|
sys.stdin.close()
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
raise SystemExit(code)
|
raise SystemExit(code)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue