Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
synchronizing output
#1
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?
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
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.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#3
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.
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