Hi,
My application has python embedded into it. I noticed that when I run any
python code the output is buffered and doesn't get flushed until my
application exits. To fix this I simply flush sys.stdout and sys.stderr
every once in while by using the following code:
//Get handle to python stdout file and flush it
PyObject *pyStdout = PySys_GetObject ("stdout");
if(pyStdout && PyFile_Check(py Stdout)) {
PyObject *result = PyObject_CallMe thod(pyStdout," flush",NULL);
Py_XDECREF(resu lt);
}
//Get handle to python stderr file and flush it
PyObject *pyStderr = PySys_GetObject ("stderr");
if(pyStderr && PyFile_Check(py Stderr)) {
PyObject *result = PyObject_CallMe thod(pyStderr," flush",NULL);
Py_XDECREF(resu lt);
}
This works for stdout but not for stderr. In order to flush stderr I have to
do:
PyRun_SimpleStr ing("sys.stderr .flush()");
Does anybody know why my first method doesn't work with stderr? I checked
and PyObject_CallMe thod is being called for both objects and no errors are
occuring. The solution I have is acceptable, but I would still like to know
why my first method didn't work.
BTW, I'm running python 2.3 on Windows XP
Thanks,
Farshid
My application has python embedded into it. I noticed that when I run any
python code the output is buffered and doesn't get flushed until my
application exits. To fix this I simply flush sys.stdout and sys.stderr
every once in while by using the following code:
//Get handle to python stdout file and flush it
PyObject *pyStdout = PySys_GetObject ("stdout");
if(pyStdout && PyFile_Check(py Stdout)) {
PyObject *result = PyObject_CallMe thod(pyStdout," flush",NULL);
Py_XDECREF(resu lt);
}
//Get handle to python stderr file and flush it
PyObject *pyStderr = PySys_GetObject ("stderr");
if(pyStderr && PyFile_Check(py Stderr)) {
PyObject *result = PyObject_CallMe thod(pyStderr," flush",NULL);
Py_XDECREF(resu lt);
}
This works for stdout but not for stderr. In order to flush stderr I have to
do:
PyRun_SimpleStr ing("sys.stderr .flush()");
Does anybody know why my first method doesn't work with stderr? I checked
and PyObject_CallMe thod is being called for both objects and no errors are
occuring. The solution I have is acceptable, but I would still like to know
why my first method didn't work.
BTW, I'm running python 2.3 on Windows XP
Thanks,
Farshid
Comment