mirror of
https://github.com/rsyslog/rsyslog.git
synced 2025-12-19 12:40:42 +01:00
Make the test program explicitly flush lines written to stdout and stderr, and do not use stdbuf to force line buffering for stdout. In Python 2 stderr was unbuffered, but in Python 3 it is block-buffered when redirected to a file/pipe. Besides, stdbuf seems to have no effect on Python 3. This solves one of the problems with this test described in #3361. The problem ocurred with Python 3 and after the addition of the wait_file_lines check in v8.40.0. The buffering that Python did caused the last two lines of the output file to be written at shutdown time. Other minor fixes and consistency enhancements in other omprog tests.
36 lines
1.4 KiB
Python
Executable File
36 lines
1.4 KiB
Python
Executable File
#!/usr/bin/env python
|
|
|
|
import sys
|
|
import os
|
|
|
|
lineLength = int(sys.argv[1])
|
|
linePrefix = "[{0:09d}] ".format(os.getpid())
|
|
|
|
logLine = sys.stdin.readline()
|
|
while logLine:
|
|
logLine = logLine.strip()
|
|
numRepeats = int(lineLength / len(logLine))
|
|
|
|
lineToStdout = (linePrefix + "[stdout] " + logLine*numRepeats)[:lineLength]
|
|
lineToStderr = (linePrefix + "[stderr] " + logLine*numRepeats)[:lineLength]
|
|
|
|
sys.stdout.write(lineToStdout + "\n")
|
|
sys.stderr.write(lineToStderr + "\n")
|
|
|
|
# Flush stdout. In both Python 2 and Python 3, stdout is block-buffered when
|
|
# redirected to a file/pipe. But be want each line to be written immediately,
|
|
# because multiple processes are writing to the same pipe, and we do not want
|
|
# lines to appear intermingled in the output file. (The flush will cause a
|
|
# single 'write' syscall, since the size of the block buffer is generally
|
|
# greater than PIPE_BUF.)
|
|
sys.stdout.flush()
|
|
|
|
# Flush stderr. This is not necessary in Python 2, since stderr is unbuffered
|
|
# (and therefore each write will be written immediately and atomically to the
|
|
# pipe). However, in Python 3 stderr is block-buffered when redirected to a
|
|
# file/pipe. (Note: in future versions of Python 3, stderr could change to
|
|
# line-buffered; see https://bugs.python.org/issue13601.)
|
|
sys.stderr.flush()
|
|
|
|
logLine = sys.stdin.readline()
|