You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/advanced.rst
+50-1Lines changed: 50 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -139,14 +139,63 @@ Configuration for the proxy host's user name, port, password and private key can
139
139
140
140
Where ``proxy.key`` is a filename containing private key to use for proxy host authentication.
141
141
142
-
In the above example, connections to the target hosts are made via ``my_proxy_user@bastion:2222`` -> ``target_host_user@<host>``.
142
+
In the above example, connections to the target hosts are made via SSH through ``my_proxy_user@bastion:2222`` -> ``target_host_user@<host>``.
143
143
144
144
.. note::
145
145
146
146
Proxy host connections are asynchronous and use the SSH protocol's native TCP tunneling - aka local port forward. No external commands or processes are used for the proxy connection, unlike the `ProxyCommand` directive in OpenSSH and other utilities.
147
147
148
148
While connections initiated by ``parallel-ssh`` are asynchronous, connections from proxy host -> target hosts may not be, depending on SSH server implementation. If only one proxy host is used to connect to a large number of target hosts and proxy SSH server connections are *not* asynchronous, this may adversely impact performance on the proxy host.
149
149
150
+
Join and Output Timeouts
151
+
**************************
152
+
153
+
*New in 1.5.0*
154
+
155
+
The native clients have timeout functionality on reading output and ``client.join``.
156
+
157
+
.. code-block:: python
158
+
159
+
from pssh.exceptions import Timeout
160
+
161
+
output = client.run_command(..)
162
+
try:
163
+
client.join(output, timeout=5)
164
+
except Timeout:
165
+
pass
166
+
167
+
.. code-block:: python
168
+
169
+
output = client.run_command(.., timeout=5)
170
+
for host, host_out in output.items():
171
+
try:
172
+
for line in host_out.stdout:
173
+
pass
174
+
for line in host_out.stderr:
175
+
pass
176
+
except Timeout:
177
+
pass
178
+
179
+
The client will raise a ``Timeout`` exception if remote commands have not finished within five seconds in the above examples.
180
+
181
+
.. note::
182
+
183
+
``join`` with a timeout forces output to be consumed as otherwise the pending output will keep the channel open and make it appear as if command has not yet finished.
184
+
185
+
To capture output when using ``join`` with a timeout, gather output first before calling ``join``, making use of output timeout as well, and/or make use of :ref:`host logger` functionality.
186
+
187
+
188
+
.. warning::
189
+
190
+
Beware of race conditions when using timeout functionality. For best results, only send one command per call to ``run_command`` when using timeout functionality.
191
+
192
+
As the timeouts are performed on ``select`` calls on the socket which is responsible for all client <-> server communication, whether or not a timeout will occur depends on what the socket is doing at that time.
193
+
194
+
Multiple commands like ``run_command('echo blah; sleep 5')`` where ``sleep 5`` is a placeholder for something taking five seconds to complete will result in a race condition as the second command may or may not have started by the time ``join`` is called or output is read which will cause timeout to *not* be raised even if the second command has not started or completed.
195
+
196
+
It is responsibility of developer to avoid these race conditions such as by only sending one command in such cases.
0 commit comments