File: parallel.py

package info (click to toggle)
roc-toolkit 0.4.0%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,684 kB
  • sloc: cpp: 102,987; ansic: 8,959; python: 6,125; sh: 942; makefile: 16; javascript: 9
file content (40 lines) | stat: -rw-r--r-- 740 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import SCons.Script
import sys
import re

def _cpu_count():
    try:
        import os
        return len(os.sched_getaffinity(0))
    except:
        pass

    try:
        import multiprocessing
        return multiprocessing.cpu_count()
    except:
        pass

    try:
        import os
        res = int(os.sysconf('SC_NPROCESSORS_ONLN'))
        if res > 0:
            return res
    except:
        pass

    try:
        import os
        res = int(os.environ['NUMBER_OF_PROCESSORS'])
        if res > 0:
            return res
    except:
        pass

    return 1

def init(env):
    for arg in sys.argv:
        if re.match(r'^(-j|--jobs=?)\d*$', arg):
            return
    SCons.Script.SetOption('num_jobs', _cpu_count())