Python Forum

Full Version: flushing output buffers
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
output to 2 open files that are buffered may get alternating output calls. when that output finally goes to a common file destination, output is mixed, but not necessarily in the same order as the original output calls like print().

i want to get the correct output mix order. does Python have a way to do that (such as a flush_all() call that knows how to do it from stored info)? or is it better to modify the files to be unbuffered? what action would you do?

in C, i did not solve this problem other that by modifying the calling code to flush the buffer after each PUT.
Can you post a piece of code having the bad behavior? I'm curious to see it at work.
(Aug-03-2023, 04:31 AM)Gribouillis Wrote: [ -> ]Can you post a piece of code having the bad behavior? I'm curious to see it at work.
i'd like to, but i don't know how to reproduce the buffering effects that sometimes happen.
Not sure if this helps, but I had to implement a flush, when redirecting in my embedded python.
In C++, it was enough to use std::endl…

maybe just end your print with a “\n”
maybe that is the cause of some or all effects. maybe it holds back a flush unless a line ends with something equivalent to a line end (in "\n\v\f\r") or when a buffer level is reached or before it would be exceeded. i'll think about ways to test that.