From c49dfcc8dcf5aec3151f7a76fd860ce0247f9bf9 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 25 May 2010 22:30:32 +0000 Subject: Issue #3798: Write sys.exit() message to sys.stderr to use stderr encoding and error handler, instead of writing to the C stderr file in utf-8 --- Python/pythonrun.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'Python/pythonrun.c') diff --git a/Python/pythonrun.c b/Python/pythonrun.c index f203618c42..db5d0a7a18 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -1106,7 +1106,13 @@ handle_system_exit(void) if (PyInt_Check(value)) exitcode = (int)PyInt_AsLong(value); else { - PyObject_Print(value, stderr, Py_PRINT_RAW); + PyObject *sys_stderr = PySys_GetObject("stderr"); + if (sys_stderr != NULL && sys_stderr != Py_None) { + PyFile_WriteObject(value, sys_stderr, Py_PRINT_RAW); + } else { + PyObject_Print(value, stderr, Py_PRINT_RAW); + fflush(stderr); + } PySys_WriteStderr("\n"); exitcode = 1; } -- cgit v1.2.1