File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change 1+ #!/usr/bin/python3
2+
3+ import os
4+ from optparse import OptionParser
5+
6+
7+ def nproc (opts ):
8+ n_cpus = os .cpu_count () if opts .all else os .process_cpu_count ()
9+
10+ print (max (n_cpus - opts .ignore , 1 ))
11+
12+
13+ if __name__ == "__main__" :
14+ parser = OptionParser (
15+ usage = "Usage: %prog [OPTION]..." ,
16+ description = "Print the number of processing units available to the process." ,
17+ add_help_option = False ,
18+ )
19+ parser .add_option ("--help" , action = "help" , help = "show usage information and exit" )
20+
21+ parser .add_option (
22+ "--all" ,
23+ action = "store_true" ,
24+ help = "print the total number of installed processors" ,
25+ )
26+
27+ parser .add_option (
28+ "--ignore" ,
29+ type = "int" ,
30+ default = 0 ,
31+ metavar = "N" ,
32+ help = "exclude up to N processors if possible" ,
33+ )
34+
35+ opts , args = parser .parse_args ()
36+
37+ if args :
38+ parser .error (f"extra operand '{ args [0 ]} '" )
39+
40+ nproc (opts )
You can’t perform that action at this time.
0 commit comments