Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 13a1fde

Browse files
committed
Partially revert #1074011; don't try to fflush stdin.
Backported to 2.3 and 2.4.
1 parent bc029af commit 13a1fde

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

Misc/NEWS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ What's New in Python 2.5 alpha 1?
1010
Core and builtins
1111
-----------------
1212

13-
- Bug #1074011: closing sys.std{in,out,err} now causes a flush() and
13+
- Bug #1074011: closing sys.std{out,err} now causes a flush() and
1414
an ferror() call.
1515

1616
- min() and max() now support key= arguments with the same meaning as in

Python/sysmodule.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,16 @@ _PySys_Init(void)
947947
m = Py_InitModule3("sys", sys_methods, sys_doc);
948948
sysdict = PyModule_GetDict(m);
949949

950-
sysin = PyFile_FromFile(stdin, "<stdin>", "r", _check_and_flush);
950+
/* Closing the standard FILE* if sys.std* goes aways causes problems
951+
* for embedded Python usages. Closing them when somebody explicitly
952+
* invokes .close() might be possible, but the FAQ promises they get
953+
* never closed. However, we still need to get write errors when
954+
* writing fails (e.g. because stdout is redirected), so we flush the
955+
* streams and check for errors before the file objects are deleted.
956+
* On OS X, fflush()ing stdin causes an error, so we exempt stdin
957+
* from that procedure.
958+
*/
959+
sysin = PyFile_FromFile(stdin, "<stdin>", "r", NULL);
951960
sysout = PyFile_FromFile(stdout, "<stdout>", "w", _check_and_flush);
952961
syserr = PyFile_FromFile(stderr, "<stderr>", "w", _check_and_flush);
953962
if (PyErr_Occurred())

0 commit comments

Comments
 (0)