diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 16:28:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 16:28:20 +0000 |
commit | dcc721a95bef6f0d8e6d8775b8efe33e5aecd562 (patch) | |
tree | 66a2774cd0ee294d019efd71d2544c70f42b2842 /tests/testsuites/omprog-output-capture-mt-bin.py | |
parent | Initial commit. (diff) | |
download | rsyslog-dcc721a95bef6f0d8e6d8775b8efe33e5aecd562.tar.xz rsyslog-dcc721a95bef6f0d8e6d8775b8efe33e5aecd562.zip |
Adding upstream version 8.2402.0.upstream/8.2402.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/testsuites/omprog-output-capture-mt-bin.py')
-rwxr-xr-x | tests/testsuites/omprog-output-capture-mt-bin.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/testsuites/omprog-output-capture-mt-bin.py b/tests/testsuites/omprog-output-capture-mt-bin.py new file mode 100755 index 0000000..22cb553 --- /dev/null +++ b/tests/testsuites/omprog-output-capture-mt-bin.py @@ -0,0 +1,35 @@ +# call this via "python[3] script name" + +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() |