Use only a single diff executor
This commit is contained in:
parent
42cabace47
commit
927bfcd37a
@ -205,9 +205,13 @@ def parse_patch(raw):
|
|||||||
|
|
||||||
class Differ:
|
class Differ:
|
||||||
|
|
||||||
|
diff_executor = None
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.jmap = {}
|
self.jmap = {}
|
||||||
self.jobs = []
|
self.jobs = []
|
||||||
|
if Differ.diff_executor is None:
|
||||||
|
Differ.diff_executor = self.diff_executor = concurrent.futures.ThreadPoolExecutor(max_workers=os.cpu_count())
|
||||||
|
|
||||||
def add_diff(self, file1, file2):
|
def add_diff(self, file1, file2):
|
||||||
self.jmap[file1] = file2
|
self.jmap[file1] = file2
|
||||||
@ -216,26 +220,26 @@ class Differ:
|
|||||||
def __call__(self, context=3):
|
def __call__(self, context=3):
|
||||||
global left_lines, right_lines
|
global left_lines, right_lines
|
||||||
ans = {}
|
ans = {}
|
||||||
with concurrent.futures.ThreadPoolExecutor(max_workers=os.cpu_count()) as executor:
|
executor = Differ.diff_executor
|
||||||
jobs = {executor.submit(run_diff, key, self.jmap[key], context): key for key in self.jobs}
|
jobs = {executor.submit(run_diff, key, self.jmap[key], context): key for key in self.jobs}
|
||||||
for future in concurrent.futures.as_completed(jobs):
|
for future in concurrent.futures.as_completed(jobs):
|
||||||
key = jobs[future]
|
key = jobs[future]
|
||||||
left_path, right_path = key, self.jmap[key]
|
left_path, right_path = key, self.jmap[key]
|
||||||
try:
|
try:
|
||||||
ok, returncode, output = future.result()
|
ok, returncode, output = future.result()
|
||||||
except FileNotFoundError as err:
|
except FileNotFoundError as err:
|
||||||
return 'Could not find the {} executable. Is it in your PATH?'.format(err.filename)
|
return 'Could not find the {} executable. Is it in your PATH?'.format(err.filename)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return 'Running git diff for {} vs. {} generated an exception: {}'.format(left_path, right_path, e)
|
return 'Running git diff for {} vs. {} generated an exception: {}'.format(left_path, right_path, e)
|
||||||
if not ok:
|
if not ok:
|
||||||
return output + '\nRunning git diff for {} vs. {} failed'.format(left_path, right_path)
|
return output + '\nRunning git diff for {} vs. {} failed'.format(left_path, right_path)
|
||||||
left_lines = lines_for_path(left_path)
|
left_lines = lines_for_path(left_path)
|
||||||
right_lines = lines_for_path(right_path)
|
right_lines = lines_for_path(right_path)
|
||||||
try:
|
try:
|
||||||
patch = parse_patch(output)
|
patch = parse_patch(output)
|
||||||
except Exception:
|
except Exception:
|
||||||
import traceback
|
import traceback
|
||||||
return traceback.format_exc() + '\nParsing diff for {} vs. {} failed'.format(left_path, right_path)
|
return traceback.format_exc() + '\nParsing diff for {} vs. {} failed'.format(left_path, right_path)
|
||||||
else:
|
else:
|
||||||
ans[key] = patch
|
ans[key] = patch
|
||||||
return ans
|
return ans
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user