Message 322055 - Python tracker

Message322055

Author Yonatan Zunger
Recipients Yonatan Zunger, docs@python, terry.reedy
Date 2018-07-21.01:09:36
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1532135377.41.0.56676864532.issue34115@psf.upfronthosting.co.za>
In-reply-to
Content
Testing your code sample on OS X (10.13.6) with Python 3.6.2:

- quit() in the console yields

Exc 0: closed is True
Python 3.6.2 (default, Apr 17 2018, 12:29:33) 
[GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> Traceback (most recent call last):
  File "./test.py", line 6, in <module>
    code.InteractiveConsole().interact()
  File "/Users/zunger/.pyenv/versions/3.6.2/lib/python3.6/code.py", line 228, in interact
    line = self.raw_input(prompt)
  File "/Users/zunger/.pyenv/versions/3.6.2/lib/python3.6/code.py", line 275, in raw_input
    return input(prompt)
ValueError: I/O operation on closed file.

- ^D and raise SystemExit in console both yield:

Python 3.6.2 (default, Apr 17 2018, 12:29:33) 
[GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> ^D
now exiting InteractiveConsole...
Try 0: closed is False
Python 3.6.2 (default, Apr 17 2018, 12:29:33) 
[GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> ^D
now exiting InteractiveConsole...
Try 1: closed is False


So it looks like the issue is specific to quit(), as you say. I'm not sure I understand what the purpose of the sys.stdin.close() call is, though: why would we *want* to alert the parent shell in some way beyond a SystemExit as the default (non-overrideable) behavior? This may be a documentation issue, but it seems extremely surprising to me; no other function does this additional thing, even when raising a SystemExit. I would think that any caller which is running InteractiveConsole.interact() and also wants to do something when it finishes would want to handle that additional logic itself.
History
Date User Action Args
2018-07-21 01:09:37Yonatan Zungersetrecipients: + Yonatan Zunger, terry.reedy, docs@python
2018-07-21 01:09:37Yonatan Zungersetmessageid: <1532135377.41.0.56676864532.issue34115@psf.upfronthosting.co.za>
2018-07-21 01:09:37Yonatan Zungerlinkissue34115 messages
2018-07-21 01:09:36Yonatan Zungercreate