Skip to content

Commit

Permalink
Improve logging output of CommandPool.run()
Browse files Browse the repository at this point in the history
  • Loading branch information
xolox committed May 24, 2015
1 parent 62051e3 commit 13a869a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion executor/__init__.py
Expand Up @@ -60,7 +60,7 @@
)

# Semi-standard module versioning.
__version__ = '2.2.1'
__version__ = '2.2.2'

# Initialize a logger.
logger = logging.getLogger(__name__)
Expand Down
15 changes: 11 additions & 4 deletions executor/concurrent.py
Expand Up @@ -22,7 +22,7 @@
from executor.writable_property import default_property

# External dependencies.
from humanfriendly import Spinner, Timer
from humanfriendly import pluralize, Spinner, Timer

# Initialize a logger.
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -125,16 +125,23 @@ def run(self):
"""
# Start spawning processes to execute the commands.
timer = Timer()
logger.debug("Preparing to run %i commands with a concurrency of %i ..", self.num_commands, self.concurrency)
logger.debug("Preparing to run %s with a concurrency of %i ..",
pluralize(self.num_commands, "command"),
self.concurrency)
with Spinner(timer=timer) as spinner:
while not self.is_finished:
self.spawn()
self.collect()
spinner.step(label="Waiting for %i/%i commands" % (self.num_commands - self.num_finished, self.num_commands))
label_format = "Waiting for %i/%i %s"
waiting_for = self.num_commands - self.num_finished
commands_pluralized = "command" if self.num_commands == 1 else "commands"
spinner.step(label=label_format % (waiting_for, self.num_commands, commands_pluralized))
spinner.sleep()
# Collect the output and return code of any commands not yet collected.
self.collect()
logger.debug("Finished running %i commands in %s.", self.num_commands, timer)
logger.debug("Finished running %s in %s.",
pluralize(self.num_commands, "command"),
timer)
# Report the results to the caller.
return dict(self.commands)

Expand Down

0 comments on commit 13a869a

Please sign in to comment.