From dfcee2e41e9b051798f642ef703182a32ca38f3c Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 12 Sep 2012 10:34:14 +0200 Subject: [PATCH] 0000831: python print causes File descriptor error on windows --- src/Base/Interpreter.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/Base/Interpreter.cpp b/src/Base/Interpreter.cpp index a1ddd5a7a..427e439dc 100644 --- a/src/Base/Interpreter.cpp +++ b/src/Base/Interpreter.cpp @@ -38,6 +38,7 @@ #include "PyTools.h" #include "Exception.h" #include "PyObjectBase.h" +#include char format2[1024]; //Warning! Can't go over 512 characters!!! @@ -89,6 +90,36 @@ SystemExitException::SystemExitException(const SystemExitException &inst) // --------------------------------------------------------- +// Fixes #0000831: python print causes File descriptor error on windows +class PythonStdOutput : public Py::PythonExtension +{ +public: + static void init_type(void) + { + behaviors().name("PythonStdOutput"); + behaviors().doc("Python standard output"); + add_varargs_method("write",&PythonStdOutput::write,"write()"); + add_varargs_method("flush",&PythonStdOutput::flush,"flush()"); + } + + PythonStdOutput() + { + } + ~PythonStdOutput() + { + } + + Py::Object write(const Py::Tuple&) + { + return Py::None(); + } + Py::Object flush(const Py::Tuple&) + { + return Py::None(); + } +}; + +// --------------------------------------------------------- InterpreterSingleton::InterpreterSingleton() { @@ -311,6 +342,10 @@ const char* InterpreterSingleton::init(int argc,char *argv[]) PyEval_InitThreads(); Py_Initialize(); PySys_SetArgv(argc, argv); + PythonStdOutput::init_type(); + PythonStdOutput* out = new PythonStdOutput(); + PySys_SetObject("stdout", out); + PySys_SetObject("stderr", out); this->_global = PyEval_SaveThread(); }