[Reproducible-commits] [diffoscope] 07/17: XXX tentative parallel
Jérémy Bobbio
lunar at moszumanska.debian.org
Tue Dec 8 18:15:20 UTC 2015
This is an automated email from the git hooks/post-receive script.
lunar pushed a commit to branch pu/parallel2
in repository diffoscope.
commit fee8a9883df607c3b630c3b5d455ab5596bf9434
Author: Jérémy Bobbio <lunar at debian.org>
Date: Wed Nov 18 16:57:15 2015 +0000
XXX tentative parallel
---
diffoscope/__main__.py | 6 ++++++
diffoscope/config.py | 20 ++++++++++++++++++++
diffoscope/difference.py | 5 ++++-
3 files changed, 30 insertions(+), 1 deletion(-)
diff --git a/diffoscope/__main__.py b/diffoscope/__main__.py
index c027b54..40f1ef7 100644
--- a/diffoscope/__main__.py
+++ b/diffoscope/__main__.py
@@ -66,6 +66,10 @@ def create_parser():
help='maximum number of lines fed to diff (default: %d)' %
Config.general.max_diff_input_lines,
default=Config.general.max_diff_input_lines)
+ parser.add_argument('--max-workers', dest='max_workers', type=int,
+ help='maximum number of concurrent workers (default: %d)' %
+ Config.general.max_workers,
+ default=Config.general.max_workers)
parser.add_argument('--fuzzy-threshold', dest='fuzzy_threshold', type=int,
help='threshold for fuzzy-matching '
'(0 to disable, %d is default, 400 is high fuzziness)' %
@@ -115,11 +119,13 @@ def run_diffoscope(parsed_args):
Config.general.max_report_size = parsed_args.max_report_size
Config.general.fuzzy_threshold = parsed_args.fuzzy_threshold
Config.general.new_file = parsed_args.new_file
+ Config.general.max_workers = parsed_args.max_workers
if parsed_args.debug:
logger.setLevel(logging.DEBUG)
set_locale()
difference = diffoscope.comparators.compare_root_paths(
parsed_args.file1, parsed_args.file2)
+ Config.general.executor.shutdown(wait=True)
if difference:
if parsed_args.html_output:
with make_printer(parsed_args.html_output) as print_func:
diff --git a/diffoscope/config.py b/diffoscope/config.py
index 5087306..dae5dff 100644
--- a/diffoscope/config.py
+++ b/diffoscope/config.py
@@ -18,6 +18,10 @@
# along with diffoscope. If not, see <http://www.gnu.org/licenses/>.
+from concurrent.futures import ThreadPoolExecutor
+import os
+
+
# From http://stackoverflow.com/a/7864317
# Credits to kylealanhale
class classproperty(property):
@@ -32,6 +36,8 @@ class Config(object):
self._max_report_size = 2000 * 2 ** 10 # 2000 kB
self._fuzzy_threshold = 60
self._new_file = False
+ self._max_workers = os.cpu_count()
+ self._executor = ThreadPoolExecutor(max_workers=self._max_workers)
@classproperty
def general(cls):
@@ -78,3 +84,17 @@ class Config(object):
@new_file.setter
def new_file(self, value):
self._new_file = value
+
+ @property
+ def max_workers(self):
+ return self._max_workers
+
+ @max_workers.setter
+ def max_workers(self, value):
+ self._max_workers = value
+ self._executor.shutdown(wait=False)
+ self._executor = ThreadPoolExecutor(max_workers=value)
+
+ @property
+ def executor(self):
+ return self._executor
diff --git a/diffoscope/difference.py b/diffoscope/difference.py
index f5a18a9..31af5c8 100644
--- a/diffoscope/difference.py
+++ b/diffoscope/difference.py
@@ -17,6 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with diffoscope. If not, see <http://www.gnu.org/licenses/>.
+from concurrent.futures import Future
from contextlib import contextmanager
from io import StringIO
import os
@@ -391,6 +392,8 @@ class Difference(object):
@property
def unified_diff(self):
+ if isinstance(self._unified_diff, Future):
+ self._unified_diff = self._unified_diff.result()
return self._unified_diff
@unified_diff.setter
@@ -409,7 +412,7 @@ class Difference(object):
if self._unified_diff is None:
difference.unified_diff = None
else:
- difference.unified_diff = reverse_unified_diff(self._unified_diff)
+ difference.unified_diff = reverse_unified_diff(self.unified_diff)
logger.debug('reverse orig %s %s', self._source1, self._source2)
difference.add_details([d.get_reverse() for d in self._details])
return difference
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git
More information about the Reproducible-commits
mailing list