Python Forum

Full Version: synchronizing output
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
if my code is going to output a message to stderr, it should flush stdout before that so the kernel gets the write syscalls in the right order. but what about other files that a few rare scriptsmight be using to output to the display? is there a way to flush everything? is there a way to get a list of file references this interpretor instance has open?
You can flush manually, what is a really annoying.
Yesterday I played around with systemd services and sockets.
There is the possibility to open a socket (like inetd) and when a connection has been established,
systemd can exchange stdin and stdout with the active socket. The problem is, that reading data should happen unbuffered.
No problem, the Python interpreter has a switch for it.

printer.py:
import time

for i in range(200):
    print('.', end='')
    time.sleep(0.1)
Now run this script one time normal, you won't see any progress until the loop is finished.
Run the same script with python -u scriptname.
i'm just concerned with the in-process buffering in python. if there is a way to have python cause any and every attempt to open any tty, fd 1, or fd 2 be done in unbuffered mode, i want to do it. if there is no such way, no big deal as this issue should be very rare.

this is for a debugging module.