@@ -27,7 +27,6 @@ import collections
2727import configparser
2828import fnmatch
2929import glob
30- import multiprocessing
3130import os
3231import re
3332import pty
@@ -1180,6 +1179,15 @@ def terminal_working():
11801179 return False
11811180
11821181
1182+ def get_cpu_count ():
1183+ try :
1184+ sched_getaffinity = os .sched_getaffinity
1185+ except AttributeError :
1186+ return os .cpu_count () or 1
1187+ else :
1188+ return len (sched_getaffinity (0 ))
1189+
1190+
11831191def main ():
11841192 (checks , flags ) = parse_conf ()
11851193 all_checks = set (checks .keys ())
@@ -1214,7 +1222,7 @@ def main():
12141222 )
12151223 ap .add_argument ('--jobs' , '-j' , metavar = 'N' , type = int , nargs = '?' ,
12161224 help = "passed to tools that can parallelize their checks" ,
1217- default = 1 ).completer = RangeCompleter (1 , multiprocessing . cpu_count ())
1225+ default = 1 ).completer = RangeCompleter (1 , get_cpu_count ())
12181226 ap .add_argument ('--checks' , '-c' , metavar = 'selectors' , nargs = 1 ,
12191227 help = "alter the set of checks to be run based on check names"
12201228 " (example: = cppcheck + lintian duck - duck)" ,
@@ -1299,7 +1307,7 @@ def main():
12991307 set_debian_substvars (checks )
13001308 sys .exit ()
13011309 if options .jobs is None :
1302- options .jobs = multiprocessing . cpu_count ()
1310+ options .jobs = get_cpu_count ()
13031311 jobs = options .jobs
13041312 run = options .commands == 'run'
13051313 verbosity = options .command_verbosity
0 commit comments