summaryrefslogtreecommitdiffstats
path: root/pre_commit/xargs.py
diff options
context:
space:
mode:
Diffstat (limited to 'pre_commit/xargs.py')
-rw-r--r--pre_commit/xargs.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/pre_commit/xargs.py b/pre_commit/xargs.py
index 31be6f3..a7493c0 100644
--- a/pre_commit/xargs.py
+++ b/pre_commit/xargs.py
@@ -25,6 +25,14 @@ TRet = TypeVar('TRet')
def cpu_count() -> int:
try:
+ # On systems that support it, this will return a more accurate count of
+ # usable CPUs for the current process, which will take into account
+ # cgroup limits
+ return len(os.sched_getaffinity(0))
+ except AttributeError:
+ pass
+
+ try:
return multiprocessing.cpu_count()
except NotImplementedError:
return 1
@@ -170,7 +178,8 @@ def xargs(
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