Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
flushing output buffers
#1
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.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
Can you post a piece of code having the bad behavior? I'm curious to see it at work.
Reply
#3
(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.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#4
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”
Skaperen likes this post
Reply
#5
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.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020