Skip to content

Commit

Permalink
Merge pull request #2971 from chriskuehl/fix-signal-death
Browse files Browse the repository at this point in the history
Fix exit code for commands terminated by signals
  • Loading branch information
asottile committed Aug 22, 2023
2 parents a1f1d19 + 5a4b5b1 commit 0c3d605
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pre_commit/xargs.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ def run_cmd_partition(
results = thread_map(run_cmd_partition, partitions)

for proc_retcode, proc_out, _ in results:
retcode = max(retcode, proc_retcode)
if abs(proc_retcode) > abs(retcode):
retcode = proc_retcode
stdout += proc_out

return retcode, stdout
9 changes: 9 additions & 0 deletions tests/xargs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,15 @@ def test_xargs_retcode_normal():
assert ret == 5


@pytest.mark.xfail(sys.platform == 'win32', reason='posix only')
def test_xargs_retcode_killed_by_signal():
ret, _ = xargs.xargs(
parse_shebang.normalize_cmd(('bash', '-c', 'kill -9 $$', '--')),
('foo', 'bar'),
)
assert ret == -9


def test_xargs_concurrency():
bash_cmd = parse_shebang.normalize_cmd(('bash', '-c'))
print_pid = ('sleep 0.5 && echo $$',)
Expand Down

0 comments on commit 0c3d605

Please sign in to comment.