From 95de7d19cfa9ed13360772832ef88e70757df9d9 Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 1 Oct 2012 16:38:43 +0200 Subject: [PATCH] Replace Python std output only for GUI application and not for CLI --- src/Base/Interpreter.cpp | 11 ++++++++--- src/Base/Interpreter.h | 1 + src/Gui/Application.cpp | 1 + 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Base/Interpreter.cpp b/src/Base/Interpreter.cpp index 427e439dc..b9676bb9b 100644 --- a/src/Base/Interpreter.cpp +++ b/src/Base/Interpreter.cpp @@ -343,15 +343,20 @@ const char* InterpreterSingleton::init(int argc,char *argv[]) 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(); } return Py_GetPath(); } +void InterpreterSingleton::replaceStdOutput() +{ + PyGILStateLocker locker; + PythonStdOutput* out = new PythonStdOutput(); + PySys_SetObject("stdout", out); + PySys_SetObject("stderr", out); +} + int InterpreterSingleton::cleanup(void (*func)(void)) { return Py_AtExit( func ); diff --git a/src/Base/Interpreter.h b/src/Base/Interpreter.h index 9f32d68d3..a055e8aa2 100644 --- a/src/Base/Interpreter.h +++ b/src/Base/Interpreter.h @@ -193,6 +193,7 @@ public: /// init the interpreter and returns the module search path const char* init(int argc,char *argv[]); int runCommandLine(const char *prompt); + void replaceStdOutput(); static InterpreterSingleton &Instance(void); static void Destruct(void); //@} diff --git a/src/Gui/Application.cpp b/src/Gui/Application.cpp index 53dec5681..b969ffb98 100644 --- a/src/Gui/Application.cpp +++ b/src/Gui/Application.cpp @@ -1403,6 +1403,7 @@ static void init_resources() void Application::initApplication(void) { try { + Base::Interpreter().replaceStdOutput(); initTypes(); new Base::ScriptProducer( "FreeCADGuiInit", FreeCADGuiInit ); init_resources();