fix user_guides/multiplex.rst (#3130)

Signed-off-by: Longin-Yu <longinyh@gmail.com>
This commit is contained in:
Hao Yu 2023-06-07 02:28:15 +08:00 committed by GitHub
parent 78439ebbe1
commit 84414e343e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 11 deletions

View File

@ -16,10 +16,13 @@ Prepare the command we are going to use. It prints "hello stdout"
in `stdout`, followed by "hello stderr" in `stderr`: in `stdout`, followed by "hello stderr" in `stderr`:
>>> cmd = '/bin/sh -c "echo hello stdout ; echo hello stderr >&2"' >>> cmd = '/bin/sh -c "echo hello stdout ; echo hello stderr >&2"'
We'll run this command with all four the combinations of ``stream`` We'll run this command with all four the combinations of ``stream``
and ``demux``. and ``demux``.
With ``stream=False`` and ``demux=False``, the output is a string With ``stream=False`` and ``demux=False``, the output is a string
that contains both the `stdout` and the `stderr` output: that contains both the `stdout` and the `stderr` output:
>>> res = container.exec_run(cmd, stream=False, demux=False) >>> res = container.exec_run(cmd, stream=False, demux=False)
>>> res.output >>> res.output
b'hello stderr\nhello stdout\n' b'hello stderr\nhello stdout\n'
@ -52,15 +55,8 @@ Traceback (most recent call last):
File "<stdin>", line 1, in <module> File "<stdin>", line 1, in <module>
StopIteration StopIteration
Finally, with ``stream=False`` and ``demux=True``, the whole output Finally, with ``stream=False`` and ``demux=True``, the output is a tuple ``(stdout, stderr)``:
is returned, but the streams are still separated:
>>> res = container.exec_run(cmd, stream=True, demux=True) >>> res = container.exec_run(cmd, stream=False, demux=True)
>>> next(res.output) >>> res.output
(b'hello stdout\n', None) (b'hello stdout\n', b'hello stderr\n')
>>> next(res.output)
(None, b'hello stderr\n')
>>> next(res.output)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
StopIteration