This code raises a ValueError: import code c = code.InteractiveConsole() c.interact() import sys sys.stdout.close() because the InteractiveConsole uses raw_input() to display its prompt. I'm not sure where the correct place to fix this is. One possible way is to allow raw_input() to take optional arguments to use instead of sys.stdin and sys.stdout. Another (easier?) way to fix this problem might be to beef up InteractiveConsole.raw_input() a bit. I'm open to either option, but I think InteractiveConsole needs to continue working even if the user closes sys.stdout. This applies to the 2.4 and 2.5 branches as well as the trunk.