diff options
author | Claudiu Popa <pcmanticore@gmail.com> | 2018-10-01 07:44:36 +0200 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2018-10-01 07:51:50 +0200 |
commit | b6162e8fa1963057f6f1eb11ff2c90ea96994430 (patch) | |
tree | 5ddf2b1f3a8fb49db427c2314457d4a04a0442b6 | |
parent | 2698cbe56b44df7974de1c3374db8700296c6fad (diff) | |
download | pylint-git-b6162e8fa1963057f6f1eb11ff2c90ea96994430.tar.gz |
Obtain the correct number of CPUs for virtualized or containerized environments.
Close #2519
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | pylint/lint.py | 13 |
2 files changed, 16 insertions, 1 deletions
@@ -13,6 +13,10 @@ Release date: TBA Close #2485 + * Obtain the correct number of CPUs for virtualized or containerized environments. + + Close #2519 + * Change ``unbalanced-tuple-unpacking`` back to a warning. It used to be a warning until a couple of years ago, after it was promoted to diff --git a/pylint/lint.py b/pylint/lint.py index 3c21bcabf..76d953f2b 100644 --- a/pylint/lint.py +++ b/pylint/lint.py @@ -233,6 +233,17 @@ MSGS = { } +def _cpu_count() -> int: + """Use sched_affinity if available for virtualized or containerized environments.""" + sched_getaffinity = getattr(os, "sched_getaffinity", None) + if sched_getaffinity: + # pylint: disable=not-callable + return len(sched_getaffinity(0)) + if multiprocessing: + return multiprocessing.cpu_count() + return 1 + + if multiprocessing is not None: class ChildLinter(multiprocessing.Process): @@ -1589,7 +1600,7 @@ group are mutually exclusive.", linter.set_option("jobs", 1) else: if linter.config.jobs == 0: - linter.config.jobs = multiprocessing.cpu_count() + linter.config.jobs = _cpu_count() # insert current working directory to the python path to have a correct # behaviour |