Skip to content

Commit

Permalink
Expose the CPU count of execution contexts
Browse files Browse the repository at this point in the history
  • Loading branch information
xolox committed May 30, 2015
1 parent 159fe70 commit 91d9bf5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion executor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
)

# Semi-standard module versioning.
__version__ = '4.3'
__version__ = '4.4'

# Initialize a logger.
logger = logging.getLogger(__name__)
Expand Down
14 changes: 14 additions & 0 deletions executor/contexts.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def details_about_system(context):

# Standard library modules.
import logging
import multiprocessing
import socket

# Modules included in our package.
Expand Down Expand Up @@ -259,6 +260,11 @@ def start_interactive_shell(self, **options):
cmd.start()
return cmd

@property
def cpu_count(self):
"""The number of CPUs in the system (an integer)."""
raise NotImplementedError()

def __enter__(self):
self.undo_stack.append([])
return self
Expand All @@ -274,6 +280,10 @@ class LocalContext(AbstractContext):

"""Context for executing commands on the local system."""

@property
def cpu_count(self):
return multiprocessing.cpu_count()

def prepare_command(self, command, options):
return ExternalCommand(*command, **self.merge_options(options))

Expand All @@ -297,6 +307,10 @@ def __init__(self, ssh_alias, **options):
super(RemoteContext, self).__init__(**options)
self.ssh_alias = ssh_alias

@property
def cpu_count(self):
return int(self.capture('nproc'))

def prepare_command(self, command, options):
return RemoteCommand(self.ssh_alias, *command, **self.merge_options(options))

Expand Down

0 comments on commit 91d9bf5

Please sign in to comment.