diff --git a/Lib/os.py b/Lib/os.py index 35842cedf14fc7..bb16aafb145623 100644 --- a/Lib/os.py +++ b/Lib/os.py @@ -1138,7 +1138,18 @@ def add_dll_directory(path): ) -if _exists('sched_getaffinity'): +def _is_cpu_overrided(): + is_overrided = False + env_opt = environ.get('PYTHONCPUCOUNT', None) + xopt = sys._xoptions.get('cpu_count', None) + if not any((env_opt, xopt)): + return False + if xopt == 'default': + return False + return True + + +if _exists('sched_getaffinity') and not _is_cpu_overrided(): def process_cpu_count(): """ Get the number of CPUs of the current process.