summaryrefslogtreecommitdiffstats
path: root/pre_commit/xargs.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-09-04 09:08:20 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-09-04 09:08:20 +0000
commit6b73455b1719f4bfff006c7d9881935cc1e6a350 (patch)
tree393586e5ce18b866b8382c6a1ead7922d4b37039 /pre_commit/xargs.py
parentReleasing debian version 3.3.3-2. (diff)
downloadpre-commit-6b73455b1719f4bfff006c7d9881935cc1e6a350.tar.xz
pre-commit-6b73455b1719f4bfff006c7d9881935cc1e6a350.zip
Merging upstream version 3.4.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
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