Issue 11730: Setting Invalid sys.stdin in interactive mode => loop forever. (original) (raw)
Setting sys.stdin to an invalid input stream under interactive mode causes interpreter run loop forever:
Python 3.3a0 (default:22ae2b002865+, Mar 30 2011, 21:17:03) [GCC 4.4.4] on linux2 Type "help", "copyright", "credits" or "license" for more information.
import sys [57804 refs] sys.stdin = None [57809 refs] [57809 refs] [57809 refs] [57809 refs] [57809 refs] ......
Not only setting to None but also to any other invalid input stream could cause this. It's because in the beginning of PyRun_InteractiveOneFlags(), in order to get stdin encoding, the code tries to get sys.stdin and check if it's valid(not NULL, not None, has "encoding" attribute), if not, return -1 directly, then the loop in PyRun_InteractLoopFlags() continues and does the same thing. I think this should be fixed by using the Py_FileSystemDefaultEncoding instead when sys.stdin is invalid.