This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Yonatan Zunger
Recipients Yonatan Zunger
Date 2018-07-14.22:49:43
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1531608583.62.0.56676864532.issue34115@psf.upfronthosting.co.za>
In-reply-to
Content
code.InteractiveConsole.interact() closes stdin on exit, which can be very surprising to successive code, not least future calls to interact(). A simple repro with a workaround is:

import code
import io
import os
import sys

def run():
    print(sys.stdin.buffer.raw)
    dupstdin = os.dup(0)
    try:
        code.InteractiveConsole().interact()
    except SystemExit:
        pass
    finally:
        # Workaround: Without this line, the second call to run() will fail with a ValueError when
        # it tries to call input().
        sys.stdin = io.TextIOWrapper(
            io.BufferedReader(io.FileIO(dupstdin, mode='rb', closefd=False)),
            encoding='utf8')

run()
run()


- The exciting behavior appears to happen inside the exec() of a 'quit()' command, and I haven't searched it out further.
- That behavior inside exec() is likely there for a good reason, in which case the best fix is probably to just save and restore stdin in the code library.
History
Date User Action Args
2018-07-14 22:49:43Yonatan Zungersetrecipients: + Yonatan Zunger
2018-07-14 22:49:43Yonatan Zungersetmessageid: <1531608583.62.0.56676864532.issue34115@psf.upfronthosting.co.za>
2018-07-14 22:49:43Yonatan Zungerlinkissue34115 messages
2018-07-14 22:49:43Yonatan Zungercreate