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: Changelog.rst
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,6 +10,7 @@ Changes
10
10
* Added interactive shell support to single and parallel clients - see `documentation <https://parallel-ssh.readthedocs.io/en/latest/advanced.html#interactive-shells>`_.
Copy file name to clipboardExpand all lines: doc/advanced.rst
+41-2Lines changed: 41 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -788,18 +788,21 @@ Iterators and filtering
788
788
Any type of iterator may be used as hosts list, including generator and list comprehension expressions.
789
789
790
790
:List comprehension:
791
+
791
792
.. code-block:: python
792
793
793
794
hosts = ['dc1.myhost1', 'dc2.myhost2']
794
795
client = ParallelSSHClient([h for h in hosts if h.find('dc1')])
795
796
796
797
:Generator:
798
+
797
799
.. code-block:: python
798
800
799
801
hosts = ['dc1.myhost1', 'dc2.myhost2']
800
802
client = ParallelSSHClient((h for h in hosts if h.find('dc1')))
801
803
802
804
:Filter:
805
+
803
806
.. code-block:: python
804
807
805
808
hosts = ['dc1.myhost1', 'dc2.myhost2']
@@ -808,12 +811,20 @@ Any type of iterator may be used as hosts list, including generator and list com
808
811
809
812
.. note ::
810
813
811
-
Since generators by design only iterate over a sequence once then stop, ``client.hosts`` should be re-assigned after each call to ``run_command`` when using generators as target of ``client.hosts``.
814
+
Assigning a generator to host list is possible as shown above, and the generator is consumed into a list on assignment.
815
+
816
+
Multiple calls to ``run_command`` will use the same hosts read from the provided generator.
817
+
812
818
813
819
Overriding hosts list
814
820
=======================
815
821
816
-
Hosts list can be modified in place. A call to ``run_command`` will create new connections as necessary and output will only contain output for the hosts ``run_command`` executed on.
822
+
Hosts list can be modified in place.
823
+
824
+
A call to ``run_command`` will create new connections as necessary and output will only be returned for the hosts ``run_command`` executed on.
825
+
826
+
Clients for hosts that are no longer on the host list are removed on host list assignment. Reading output from hosts removed from host list is feasible, as long as their output objects or interactive shells are in scope.
827
+
817
828
818
829
.. code-block:: python
819
830
@@ -825,3 +836,31 @@ Hosts list can be modified in place. A call to ``run_command`` will create new c
825
836
host='otherhost'
826
837
exit_code=None
827
838
<..>
839
+
840
+
841
+
When wanting to reassign host list frequently, it is best to sort or otherwise ensure order is maintained to avoid reconnections on hosts that are still in the host list but in a different order.
842
+
843
+
For example, the following will cause reconnections on both hosts, though both are still in the list.
844
+
845
+
.. code-block:: python
846
+
847
+
client.hosts = ['host1', 'host2']
848
+
client.hosts = ['host2', 'host1']
849
+
850
+
851
+
In such cases it would be best to maintain order to avoid reconnections. This is also true when adding or removing hosts in host list.
852
+
853
+
No change in clients occurs in the following case.
854
+
855
+
.. code-block:: python
856
+
857
+
client.hosts =sorted(['host1', 'host2'])
858
+
client.hosts =sorted(['host2', 'host1'])
859
+
860
+
861
+
Clients for hosts that would be removed by a reassignment can be calculated with:
0 commit comments