python类sysconf_names()的实例源码

util.py 文件源码 项目:hostapd-mana 作者: adde88 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def _detect_ncpus():
    """Detect the number of effective CPUs in the system"""
    # Snippet taken from ParallelPython
    # For Linux, Unix and MacOS
    if hasattr(os, "sysconf"):
        if "SC_NPROCESSORS_ONLN" in os.sysconf_names:
            #Linux and Unix
            ncpus = os.sysconf("SC_NPROCESSORS_ONLN")
            if isinstance(ncpus, int) and ncpus > 0:
                return ncpus
        else:
            #MacOS X
            return int(os.popen2("sysctl -n hw.ncpu")[1].read())
    #for Windows
    if "NUMBER_OF_PROCESSORS" in os.environ:
        ncpus = int(os.environ["NUMBER_OF_PROCESSORS"])
        if ncpus > 0:
            return ncpus
    #return the default value
    return 1
util.py 文件源码 项目:sslstrip-hsts-openwrt 作者: adde88 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def _detect_ncpus():
    """Detect the number of effective CPUs in the system"""
    # Snippet taken from ParallelPython
    # For Linux, Unix and MacOS
    if hasattr(os, "sysconf"):
        if "SC_NPROCESSORS_ONLN" in os.sysconf_names:
            #Linux and Unix
            ncpus = os.sysconf("SC_NPROCESSORS_ONLN")
            if isinstance(ncpus, int) and ncpus > 0:
                return ncpus
        else:
            #MacOS X
            return int(os.popen2("sysctl -n hw.ncpu")[1].read())
    #for Windows
    if "NUMBER_OF_PROCESSORS" in os.environ:
        ncpus = int(os.environ["NUMBER_OF_PROCESSORS"])
        if ncpus > 0:
            return ncpus
    #return the default value
    return 1
utils.py 文件源码 项目:zorro 作者: C-CINA 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def detect_number_of_cores():
    """
    Detects the number of cores on a system. Cribbed from pp.
    """
    # Linux, Unix and MacOS:
    if hasattr(os, "sysconf"):
        if "SC_NPROCESSORS_ONLN" in os.sysconf_names:
            # Linux & Unix:
            ncpus = os.sysconf("SC_NPROCESSORS_ONLN")
            if isinstance(ncpus, int) and ncpus > 0:
                return ncpus
        else:  # OSX:
            return int(subprocess.check_output(["sysctl", "-n", "hw.ncpu"]))
    # Windows:
    if "NUMBER_OF_PROCESSORS" in os.environ:
        ncpus = int(os.environ["NUMBER_OF_PROCESSORS"]);
        if ncpus > 0:
            return ncpus
    return 1  # Default
util.py 文件源码 项目:alive-nj 作者: rutgers-apl 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def detectCPUs():
    """
    Detects the number of CPUs on a system. Cribbed from pp.
    """
    # Linux, Unix and MacOS:
    if hasattr(os, "sysconf"):
        if "SC_NPROCESSORS_ONLN" in os.sysconf_names:
            # Linux & Unix:
            ncpus = os.sysconf("SC_NPROCESSORS_ONLN")
            if isinstance(ncpus, int) and ncpus > 0:
                return ncpus
        else: # OSX:
            return int(capture(['sysctl', '-n', 'hw.ncpu']))
    # Windows:
    if "NUMBER_OF_PROCESSORS" in os.environ:
        ncpus = int(os.environ["NUMBER_OF_PROCESSORS"])
        if ncpus > 0:
            return ncpus
    return 1 # Default
Options.py 文件源码 项目:SoCFoundationFlow 作者: mattaw 项目源码 文件源码 阅读 38 收藏 0 点赞 0 评论 0
def jobs(self):
        """
        Find the amount of cpu cores to set the default amount of tasks executed in parallel. At
        runtime the options can be obtained from :py:const:`waflib.Options.options` ::

            from waflib.Options import options
            njobs = options.jobs

        :return: the amount of cpu cores
        :rtype: int
        """
        count = int(os.environ.get('JOBS', 0))
        if count < 1:
            if 'NUMBER_OF_PROCESSORS' in os.environ:
                # on Windows, use the NUMBER_OF_PROCESSORS environment variable
                count = int(os.environ.get('NUMBER_OF_PROCESSORS', 1))
            else:
                # on everything else, first try the POSIX sysconf values
                if hasattr(os, 'sysconf_names'):
                    if 'SC_NPROCESSORS_ONLN' in os.sysconf_names:
                        count = int(os.sysconf('SC_NPROCESSORS_ONLN'))
                    elif 'SC_NPROCESSORS_CONF' in os.sysconf_names:
                        count = int(os.sysconf('SC_NPROCESSORS_CONF'))
                if not count and os.name not in ('nt', 'java'):
                    try:
                        tmp = self.cmd_and_log(['sysctl', '-n', 'hw.ncpu'], quiet=0)
                    except Exception:
                        pass
                    else:
                        if re.match('^[0-9]+$', tmp):
                            count = int(tmp)
        if count < 1:
            count = 1
        elif count > 1024:
            count = 1024
        return count
Options.py 文件源码 项目:SoCFoundationFlow 作者: mattaw 项目源码 文件源码 阅读 51 收藏 0 点赞 0 评论 0
def jobs(self):
        """
        Find the amount of cpu cores to set the default amount of tasks executed in parallel. At
        runtime the options can be obtained from :py:const:`waflib.Options.options` ::

            from waflib.Options import options
            njobs = options.jobs

        :return: the amount of cpu cores
        :rtype: int
        """
        count = int(os.environ.get('JOBS', 0))
        if count < 1:
            if 'NUMBER_OF_PROCESSORS' in os.environ:
                # on Windows, use the NUMBER_OF_PROCESSORS environment variable
                count = int(os.environ.get('NUMBER_OF_PROCESSORS', 1))
            else:
                # on everything else, first try the POSIX sysconf values
                if hasattr(os, 'sysconf_names'):
                    if 'SC_NPROCESSORS_ONLN' in os.sysconf_names:
                        count = int(os.sysconf('SC_NPROCESSORS_ONLN'))
                    elif 'SC_NPROCESSORS_CONF' in os.sysconf_names:
                        count = int(os.sysconf('SC_NPROCESSORS_CONF'))
                if not count and os.name not in ('nt', 'java'):
                    try:
                        tmp = self.cmd_and_log(['sysctl', '-n', 'hw.ncpu'], quiet=0)
                    except Exception:
                        pass
                    else:
                        if re.match('^[0-9]+$', tmp):
                            count = int(tmp)
        if count < 1:
            count = 1
        elif count > 1024:
            count = 1024
        return count
Options.py 文件源码 项目:SoCFoundationFlow 作者: mattaw 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def jobs(self):
        """
        Find the amount of cpu cores to set the default amount of tasks executed in parallel. At
        runtime the options can be obtained from :py:const:`waflib.Options.options` ::

            from waflib.Options import options
            njobs = options.jobs

        :return: the amount of cpu cores
        :rtype: int
        """
        count = int(os.environ.get('JOBS', 0))
        if count < 1:
            if 'NUMBER_OF_PROCESSORS' in os.environ:
                # on Windows, use the NUMBER_OF_PROCESSORS environment variable
                count = int(os.environ.get('NUMBER_OF_PROCESSORS', 1))
            else:
                # on everything else, first try the POSIX sysconf values
                if hasattr(os, 'sysconf_names'):
                    if 'SC_NPROCESSORS_ONLN' in os.sysconf_names:
                        count = int(os.sysconf('SC_NPROCESSORS_ONLN'))
                    elif 'SC_NPROCESSORS_CONF' in os.sysconf_names:
                        count = int(os.sysconf('SC_NPROCESSORS_CONF'))
                if not count and os.name not in ('nt', 'java'):
                    try:
                        tmp = self.cmd_and_log(['sysctl', '-n', 'hw.ncpu'], quiet=0)
                    except Exception:
                        pass
                    else:
                        if re.match('^[0-9]+$', tmp):
                            count = int(tmp)
        if count < 1:
            count = 1
        elif count > 1024:
            count = 1024
        return count
gclient_utils.py 文件源码 项目:Chromium_DepotTools 作者: p07r0457 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def NumLocalCpus():
  """Returns the number of processors.

  multiprocessing.cpu_count() is permitted to raise NotImplementedError, and
  is known to do this on some Windows systems and OSX 10.6. If we can't get the
  CPU count, we will fall back to '1'.
  """
  # Surround the entire thing in try/except; no failure here should stop gclient
  # from working.
  try:
    # Use multiprocessing to get CPU count. This may raise
    # NotImplementedError.
    try:
      import multiprocessing
      return multiprocessing.cpu_count()
    except NotImplementedError:  # pylint: disable=bare-except
      # (UNIX) Query 'os.sysconf'.
      # pylint: disable=no-member
      if hasattr(os, 'sysconf') and 'SC_NPROCESSORS_ONLN' in os.sysconf_names:
        return int(os.sysconf('SC_NPROCESSORS_ONLN'))

      # (Windows) Query 'NUMBER_OF_PROCESSORS' environment variable.
      if 'NUMBER_OF_PROCESSORS' in os.environ:
        return int(os.environ['NUMBER_OF_PROCESSORS'])
  except Exception as e:
    logging.exception("Exception raised while probing CPU count: %s", e)

  logging.debug('Failed to get CPU count. Defaulting to 1.')
  return 1
gclient_utils.py 文件源码 项目:node-gn 作者: Shouqun 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def NumLocalCpus():
  """Returns the number of processors.

  multiprocessing.cpu_count() is permitted to raise NotImplementedError, and
  is known to do this on some Windows systems and OSX 10.6. If we can't get the
  CPU count, we will fall back to '1'.
  """
  # Surround the entire thing in try/except; no failure here should stop gclient
  # from working.
  try:
    # Use multiprocessing to get CPU count. This may raise
    # NotImplementedError.
    try:
      import multiprocessing
      return multiprocessing.cpu_count()
    except NotImplementedError:  # pylint: disable=bare-except
      # (UNIX) Query 'os.sysconf'.
      # pylint: disable=no-member
      if hasattr(os, 'sysconf') and 'SC_NPROCESSORS_ONLN' in os.sysconf_names:
        return int(os.sysconf('SC_NPROCESSORS_ONLN'))

      # (Windows) Query 'NUMBER_OF_PROCESSORS' environment variable.
      if 'NUMBER_OF_PROCESSORS' in os.environ:
        return int(os.environ['NUMBER_OF_PROCESSORS'])
  except Exception as e:
    logging.exception("Exception raised while probing CPU count: %s", e)

  logging.debug('Failed to get CPU count. Defaulting to 1.')
  return 1
noded.py 文件源码 项目:noded 作者: giovtorres 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def get_sys_info():
    """
    Return dictionary of system information

    SC_NPROCESSORS_ONLN returns the number of processors which are currently
    online (i.e. available).  See os.sysconf_names for dictionary values.

    """
    return {
        "nodename": gethostname(),
        "total_logical_cpus": os.sysconf(84)
    }
gclient_utils.py 文件源码 项目:depot_tools 作者: webrtc-uwp 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def NumLocalCpus():
  """Returns the number of processors.

  multiprocessing.cpu_count() is permitted to raise NotImplementedError, and
  is known to do this on some Windows systems and OSX 10.6. If we can't get the
  CPU count, we will fall back to '1'.
  """
  # Surround the entire thing in try/except; no failure here should stop gclient
  # from working.
  try:
    # Use multiprocessing to get CPU count. This may raise
    # NotImplementedError.
    try:
      import multiprocessing
      return multiprocessing.cpu_count()
    except NotImplementedError:  # pylint: disable=bare-except
      # (UNIX) Query 'os.sysconf'.
      # pylint: disable=no-member
      if hasattr(os, 'sysconf') and 'SC_NPROCESSORS_ONLN' in os.sysconf_names:
        return int(os.sysconf('SC_NPROCESSORS_ONLN'))

      # (Windows) Query 'NUMBER_OF_PROCESSORS' environment variable.
      if 'NUMBER_OF_PROCESSORS' in os.environ:
        return int(os.environ['NUMBER_OF_PROCESSORS'])
  except Exception as e:
    logging.exception("Exception raised while probing CPU count: %s", e)

  logging.debug('Failed to get CPU count. Defaulting to 1.')
  return 1


问题


面经


文章

微信
公众号

扫码关注公众号