If sys.stdout is a tty, it typically flushes on newline. e. g. !/usr/bin/env python3 import time import sys print("No flush",end='',file=sys.stdout) time.sleep(2) print("flushed",file=sys.stdout) time.sleep(5)
will print the “flushed” 5 seconds before the script ends From: Python-list <python-list-bounces+gweatherby=uchc....@python.org> on behalf of Eryk Sun <eryk...@gmail.com> Date: Tuesday, January 3, 2023 at 1:33 PM To: c.bu...@posteo.jp <c.bu...@posteo.jp> Cc: python-list@python.org <python-list@python.org> Subject: Re: What should go to stdout/stderr and why Python logging write everything to stderr? *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** On 1/3/23, c.bu...@posteo.jp <c.bu...@posteo.jp> wrote: > > If the user request the usage info via "-h" it goes to stdout. The standard file for application output is sys.stdout. Note that sys.stdout may be buffered, particularly if it isn't a tty. When a file is buffered, writes are aggregated and only written to the OS file when the buffer fills up or is manually flushed. > Why does logging behave different? DEBUG and INFO imho should go to > stdout not stderr. The standard file for error messages and other diagnostic information is sys.stderr. This file should never be buffered. -- https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!jGBVNrRuUThZCKMmShbuvBgggwv7FBDL9h2vW-vvehPnBHdfkrJUhohhZCgsCAqlRrDluk9c526jABrLjg$<https://urldefense.com/v3/__https:/mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!jGBVNrRuUThZCKMmShbuvBgggwv7FBDL9h2vW-vvehPnBHdfkrJUhohhZCgsCAqlRrDluk9c526jABrLjg$> -- https://mail.python.org/mailman/listinfo/python-list