From 76b245e154972150b5e1f0290a3be27a07d91cea Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Wed, 14 Nov 2012 21:07:16 +0000 Subject: [PATCH] Python logger now flushes stdout after every call to writelog --- src/python/pylogger.h | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/src/python/pylogger.h b/src/python/pylogger.h index 076fa20d8..efe6d77f0 100644 --- a/src/python/pylogger.h +++ b/src/python/pylogger.h @@ -5,8 +5,6 @@ #include #include "cantera/base/logger.h" -static std::string ss = "print \"\"\" "; - namespace Cantera { @@ -15,23 +13,17 @@ namespace Cantera class Py_Logger : public Logger { public: - Py_Logger() {} + Py_Logger() { + PyRun_SimpleString("import sys"); + } virtual ~Py_Logger() {} virtual void write(const std::string& s) { - char ch = s[0]; - int n = 0; - while (ch != '\0') { - if (ch =='\n') { - ss += "\"\"\""; - PyRun_SimpleString((char*)ss.c_str()); - ss = "print \"\"\""; - } else { - ss += ch; - } - n++; - ch = s[n]; - } + std::string ss = "sys.stdout.write(\"\"\""; + ss += s; + ss += "\"\"\")"; + PyRun_SimpleString(ss.c_str()); + PyRun_SimpleString("sys.stdout.flush()"); } virtual void error(const std::string& msg) {