

def _get_num_cpus():
    'Return the number of CPUs on the system'
    try:
        return os.sysconf('SC_NPROCESSORS_ONLN')
    except ValueError:
        num = 0
        f = open('/proc/cpuinfo', 'r')
        try:
            lines = f.readlines()
        finally:
            f.close()
        for line in lines:
            if line.lower().startswith('processor'):
                num += 1
    if (num == 0):
        f = open('/proc/stat', 'r')
        try:
            lines = f.readlines()
        finally:
            f.close()
        search = re.compile('cpu\\d')
        for line in lines:
            line = search.split(' ')[0]
            if search.match(line):
                num += 1
    if (num == 0):
        raise RuntimeError("can't determine number of CPUs")
    return num

dataset/ETHPy150Open packages/psutil/psutil/_pslinux.py _get_num_cpus/VarMisuse@154/217 `line`->`search`