mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 00:04:42 +04:00
Use os.sched_getaffinity for cpu counts when available
This commit is contained in:
parent
9ebda91889
commit
ea8244b229
2 changed files with 33 additions and 2 deletions
|
|
@ -24,6 +24,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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue