Skip to content

Commit

Permalink
Add a RemoteCommandPool class
Browse files Browse the repository at this point in the history
  • Loading branch information
xolox committed May 26, 2015
1 parent 0ac67a4 commit c3c295c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion executor/__init__.py
Expand Up @@ -60,7 +60,7 @@
)

# Semi-standard module versioning.
__version__ = '3.4.1'
__version__ = '3.5'

# Initialize a logger.
logger = logging.getLogger(__name__)
Expand Down
27 changes: 26 additions & 1 deletion executor/ssh/client.py
Expand Up @@ -91,7 +91,7 @@ def foreach(hosts, *command, **options):
options.setdefault('capture', True)
# Create a command pool.
timer = Timer()
pool = CommandPool(concurrency)
pool = RemoteCommandPool(concurrency)
hosts_pluralized = pluralize(len(hosts), "host")
logger.debug("Preparing to run remote command on %s (%s) with a concurrency of %i: %s",
hosts_pluralized, concatenate(hosts), concurrency, quote(command))
Expand Down Expand Up @@ -375,6 +375,31 @@ def known_hosts_file(self, value=None):
return value


class RemoteCommandPool(CommandPool):

"""
Execute multiple remote commands concurrently.
After constructing a :class:`RemoteCommandPool` instance you add commands
to it using :func:`add()` and when you're ready to run the commands you
call :func:`run()`.
.. note:: The only difference between :class:`.CommandPool` and
:class:`RemoteCommandPool` is the default concurrency. This may
of course change in the future.
"""

def __init__(self, concurrency=DEFAULT_CONCURRENCY):
"""
Construct a :class:`RemoteCommandPool` object.
:param concurrency: Override the value of :attr:`concurrency` (an
integer, defaults to :data:`DEFAULT_CONCURRENCY`
for remote command pools).
"""
super(RemoteCommandPool, self).__init__(concurrency)


class RemoteCommandFailed(ExternalCommandFailed):
"""Raised by :func:`foreach()` when a remote command executed over SSH fails."""

Expand Down

0 comments on commit c3c295c

Please sign in to comment.