()
Return the number of logical CPUs in the system.
Return the number of logical CPUs in the system.
Return the number of logical CPUs in the system .
def cpu_count_logical():
    """Return the number of logical CPUs in the system."""
    try:
        return os.sysconf("SC_NPROCESSORS_ONLN")
    except ValueError:
        # as a second fallback we try to parse /proc/cpuinfo
        num = 0
        with open('/proc/cpuinfo', 'rb') as f:
            for line in f:
                if line.lower().startswith(b'processor'):
                    num += 1

        # unknown format (e.g. amrel/sparc architectures), see:
        # https://github.com/giampaolo/psutil/issues/200
        # try to parse /proc/stat as a last resort
        if num == 0:
            search = re.compile('cpu\d')
            with open_text('/proc/stat') as f:
                for line in f:
                    line = line.split(' ')[0]
                    if search.match(line):
                        num += 1

        if num == 0:
            # mimic os.cpu_count()
            return None
        return num
def cpu_count_logical ( ) : try : return os . sysconf ( "SC_NPROCESSORS_ONLN" ) except ValueError : # as a second fallback we try to parse /proc/cpuinfo num = 0 with open ( '/proc/cpuinfo' , 'rb' ) as f : for line in f : if line . lower ( ) . startswith ( b'processor' ) : num += 1 # unknown format (e.g. amrel/sparc architectures), see: # https://github.com/giampaolo/psutil/issues/200 # try to parse /proc/stat as a last resort if num == 0 : search = re . compile ( 'cpu\d' ) with open_text ( '/proc/stat' ) as f : for line in f : line = line . split ( ' ' ) [ 0 ] if search . match ( line ) : num += 1 if num == 0 : # mimic os.cpu_count() return None return num