diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-05-10 06:30:40 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-05-10 06:30:40 +0000 |
commit | f174d1c83b97cd7007a792255c5e132306e6c1a3 (patch) | |
tree | 0506eadfc5ef4db1ca746799d35d4610df9a9c78 /pre_commit/xargs.py | |
parent | Adding upstream version 3.2.2. (diff) | |
download | pre-commit-f174d1c83b97cd7007a792255c5e132306e6c1a3.tar.xz pre-commit-f174d1c83b97cd7007a792255c5e132306e6c1a3.zip |
Adding upstream version 3.3.1.upstream/3.3.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'pre_commit/xargs.py')
-rw-r--r-- | pre_commit/xargs.py | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/pre_commit/xargs.py b/pre_commit/xargs.py index e3af90e..31be6f3 100644 --- a/pre_commit/xargs.py +++ b/pre_commit/xargs.py @@ -3,6 +3,7 @@ from __future__ import annotations import concurrent.futures import contextlib import math +import multiprocessing import os import subprocess import sys @@ -22,6 +23,13 @@ TArg = TypeVar('TArg') TRet = TypeVar('TRet') +def cpu_count() -> int: + try: + return multiprocessing.cpu_count() + except NotImplementedError: + return 1 + + def _environ_size(_env: MutableMapping[str, str] | None = None) -> int: environ = _env if _env is not None else getattr(os, 'environb', os.environ) size = 8 * len(environ) # number of pointers in `envp` |