Flush stdout if a custom model printer has been registered.#610
Flush stdout if a custom model printer has been registered.#610
Conversation
ab5ee3a to
3afccea
Compare
|
With the last force push, this is handle on the Python side only: // ensure OS buffer is flushed
std::cout.flush()
app.print_model(Model{model}, [printer, printer_data]() { handle_error(printer(printer_data)); });
// ensure Python buffer is flushed
py::module_::import("sys").attr("stdout").attr("flush")();The two flushes are important because it seems like python directly writes large buffers without flushing previously written smaller buffers leading to tangled up output. |
3afccea to
1d0d9cb
Compare
|
If I remember correctly |
It may not be required by the standard but printf and fprintf to stdout not using the same buffer would be strange. In any case, users should stick to printf when using the C API. So I don't see a problem. And for other language bindings this has to be addressed on a case by case basis. |
Output might get tangled if a model printer is registered in Python because python manages its own output buffer. I pushed a preliminary fix. @BenKaufmann what do you think about this? Should we flush the output in general or should we just do it for the Python API? For the C/C++ APIs there should be no issues because here we do not have separate buffers.