Commit b06e89b3 authored by Juliana Oliveira's avatar Juliana Oliveira

difference: adds comparison_pool.map to command execution

If Config().parallel is True, uses comparison_pool's map method to run
file comparison asyncronously. Defaults to serial comparison.
Signed-off-by: 's avatarJuliana Oliveira <juliana.orod@gmail.com>
parent 613d4f95
...@@ -24,6 +24,8 @@ from . import feeders ...@@ -24,6 +24,8 @@ from . import feeders
from .exc import RequiredToolNotFound from .exc import RequiredToolNotFound
from .diff import diff, reverse_unified_diff, diff_split_lines from .diff import diff, reverse_unified_diff, diff_split_lines
from .excludes import command_excluded from .excludes import command_excluded
from .config import Config
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
...@@ -230,6 +232,7 @@ class Difference(object): ...@@ -230,6 +232,7 @@ class Difference(object):
@staticmethod @staticmethod
def from_command_exc(klass, path1, path2, *args, **kwargs): def from_command_exc(klass, path1, path2, *args, **kwargs):
logger.debug("Starting execution of command %s", klass)
command_args = [] command_args = []
if 'command_args' in kwargs: if 'command_args' in kwargs:
command_args = kwargs['command_args'] command_args = kwargs['command_args']
...@@ -247,8 +250,31 @@ class Difference(object): ...@@ -247,8 +250,31 @@ class Difference(object):
command.start() command.start()
return feeder, command, False return feeder, command, False
feeder1, command1, excluded1 = command_and_feeder(path1) results = {}
feeder2, command2, excluded2 = command_and_feeder(path2)
if Config().parallel:
import dill
from .parallel.comparison_pool import ComparisonPool, \
CommandFailedToExecute
pool = ComparisonPool()
try:
pool.map(command_and_feeder, args=[path1, path2], callback=results)
except CommandFailedToExecute as e:
logger.debug("Command failed while executing %s", e)
if not results:
logger.debug("Parallel execution failed or disabled. \
Falling back to serial execution.")
cmd1 = command_and_feeder(path1)
cmd2 = command_and_feeder(path2)
else:
cmd1, cmd2 = results[0], results[1]
feeder1, command1, excluded1 = cmd1
feeder2, command2, excluded2 = cmd2
if not feeder1 or not feeder2: if not feeder1 or not feeder2:
assert excluded1 or excluded2 assert excluded1 or excluded2
return None, True return None, True
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment