Skip to content

Commit

Permalink
changed commit 22b272f a bit
Browse files Browse the repository at this point in the history
- only "fix" sys.stdout if it is no tty
- make sys.stdout line buffered (to avoid too "many" write calls)
- added more detailed explanation why this is needed
  • Loading branch information
marcus-h committed May 16, 2015
1 parent 22b272f commit 56a9ab6
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions osc-wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,18 @@
pass

# avoid buffering output on pipes (bnc#930137)
if sys.stdout.name == '<stdout>':
sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
# Basically, a "print('foo')" call is translated to a corresponding
# fwrite call that writes to the stdout stream (cf. string_print
# (Objects/stringobject.c) and builtin_print (Python/bltinmodule.c));
# If no pipe is used, stdout is a tty/refers to a terminal =>
# the stream is line buffered (see _IO_file_doallocate (libio/filedoalloc.c)).
# If a pipe is used, stdout does not refer to a terminal anymore =>
# the stream is fully buffered by default (see _IO_file_doallocate).
# The following fdopen call makes stdout line buffered again (at least on
# systems that support setvbuf - if setvbuf is not supported, the stream
# remains fully buffered (see PyFile_SetBufSize (Objects/fileobject.c))).
if not os.isatty(sys.stdout.fileno()):
sys.stdout = os.fdopen(sys.stdout.fileno(), sys.stdout.mode, 1)

osccli = commandline.Osc()

Expand Down

0 comments on commit 56a9ab6

Please sign in to comment.