summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--pylint/lint.py13
2 files changed, 16 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 6e06ec4d2..eb2ea6134 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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