Skip to content

Commit 15c73c2

Browse files
author
Pan
committed
Updated docs, travis cfg
1 parent f74c8e7 commit 15c73c2

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ jobs:
133133
python: 3.6
134134
before_install: skip
135135
install: skip
136-
after_success: skip
137136
script:
138137
- docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"
139138
- ./ci/docker/build-packages.sh

doc/advanced.rst

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,19 +180,34 @@ The native clients have timeout functionality on reading output and ``client.joi
180180
181181
The client will raise a ``Timeout`` exception if remote commands have not finished within five seconds in the above examples.
182182

183+
Reading Partial Output of Commands That Do Not Terminate
184+
----------------------------------------------------------
185+
183186
In some cases, such as when the remote command never terminates unless interrupted, it is necessary to use PTY and to close the channel to force the process to be terminated before a ``join`` sans timeout can complete. For example:
184187

185188
.. code-block:: python
186189
187-
output = client.run_command('tail -f /var/log/messages', use_pty=True)
188-
client.join(output, timeout=1)
190+
output = client.run_command('tail -f /var/log/messages', use_pty=True, timeout=1)
191+
192+
# Read as many lines of output as server has sent before the timeout
193+
stdout = []
194+
for host, host_out in output.items():
195+
for host, host_out in output.items():
196+
try:
197+
for line in host_out.stdout:
198+
stdout.append(line)
199+
except Timeout:
200+
pass
201+
189202
# Closing channel which has PTY has the effect of terminating
190203
# any running processes started on that channel.
191-
for host, host_out in output:
204+
for host, host_out in output.items():
192205
client.host_clients[host].close_channel(host_out.channel)
206+
# Join is not strictly needed here as channel has already been closed and
207+
# command has finished, but is safe to use regardless.
193208
client.join(output)
194209
195-
Without a PTY, the ``join`` will complete but the remote process will be left running as per SSH protocol specifications.
210+
Without a PTY, a ``join`` call with a timeout will complete with timeout exception raised but the remote process will be left running as per SSH protocol specifications.
196211

197212
Furthermore, once reading output has timed out, it is necessary to restart the output generators as by Python design they only iterate once. This can be done as follows:
198213

@@ -205,7 +220,7 @@ Furthermore, once reading output has timed out, it is necessary to restart the o
205220
except Timeout:
206221
client.reset_output_generators(host_out)
207222
208-
Generator reset shown above is also performed automatically by calls to ``join`` and does not need to be done manually ``join`` is used after output reading.
223+
Generator reset shown above is also performed automatically by calls to ``join`` and does not need to be done manually when ``join`` is used after output reading.
209224

210225
.. note::
211226

0 commit comments

Comments
 (0)