Python logger now flushes stdout after every call to writelog
This commit is contained in:
parent
7ed2a02953
commit
76b245e154
1 changed files with 8 additions and 16 deletions
|
|
@ -5,8 +5,6 @@
|
|||
#include <string>
|
||||
#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) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue