Skip to content

Commit 2b32dce

Browse files
committed
genlast: Actually catch errors when preprocessing files
Due to a number of problems, an error calling the preprocessor wasn't making the whole genlast process fail. Now, after an execption during preprocess is printed, it is re-raised. Then, by actually collating the results of executor.map, the exception will be raised in the main thread context. Any CalledProcessError is simply converted to a nonzero exit status.
1 parent ab037bd commit 2b32dce

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

py/genlast.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def preprocess(command, output_dir, fn):
4848
process_file(fn, output_dir, output)
4949
except Exception as e:
5050
print(e, file=sys.stderr)
51+
raise
5152

5253

5354
def maybe_preprocess(command, output_dir, fn):
@@ -72,6 +73,18 @@ def maybe_preprocess(command, output_dir, fn):
7273
# Mac and Windows use 'spawn'. Uncomment this during testing to catch spawn-specific problems on Linux.
7374
# multiprocessing.set_start_method("spawn")
7475
executor = ProcessPoolExecutor(max_workers=multiprocessing.cpu_count() + 1)
75-
executor.map(maybe_preprocess, itertools.repeat(command), itertools.repeat(output_dir), check)
76-
executor.map(preprocess, itertools.repeat(command), itertools.repeat(output_dir), always)
76+
results = []
77+
try:
78+
results.extend(
79+
executor.map(
80+
maybe_preprocess, itertools.repeat(command), itertools.repeat(output_dir), check
81+
)
82+
)
83+
results.extend(
84+
executor.map(
85+
preprocess, itertools.repeat(command), itertools.repeat(output_dir), always
86+
)
87+
)
88+
except subprocess.CalledProcessError:
89+
raise SystemExit(1)
7790
executor.shutdown()

0 commit comments

Comments
 (0)