当前位置: 首页>>代码示例>>Python>>正文


Python psutil.version_info方法代码示例

本文整理汇总了Python中psutil.version_info方法的典型用法代码示例。如果您正苦于以下问题:Python psutil.version_info方法的具体用法?Python psutil.version_info怎么用?Python psutil.version_info使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在psutil的用法示例。


在下文中一共展示了psutil.version_info方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_num_cores

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import version_info [as 别名]
def get_num_cores():
        import psutil
        version = psutil.version_info
        # Installation of OpenStack Kilo uses pstuil version 1.2.1
        p = psutil.Process()
        if version >= (2, 0):
            return len(p.cpu_affinity())
        else:
            try:
                # psutil 1.2.1 has issue with large number of cores
                # https://github.com/giampaolo/psutil/issues/522
                cores = len(p.get_cpu_affinity())
            except OSError as e:
                import affinity
                cores = len(affinity.sched_getaffinity(p.pid))
            return cores 
开发者ID:cmusatyalab,项目名称:elijah-provisioning,代码行数:18,代码来源:configuration.py

示例2: test_version

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import version_info [as 别名]
def test_version(self):
        self.assertEqual('.'.join([str(x) for x in psutil.version_info]),
                         psutil.__version__) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:5,代码来源:test_misc.py

示例3: LogHostMemoryUsage

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import version_info [as 别名]
def LogHostMemoryUsage(top_n=10, level=logging.INFO):
  if not psutil:
    logging.warning('psutil module is not found, skipping logging memory info')
    return
  if psutil.version_info < (2, 0):
    logging.warning('psutil %s too old, upgrade to version 2.0 or higher'
                    ' for memory usage information.', psutil.__version__)
    return

  # TODO(crbug.com/777865): Remove the following pylint disable. Even if we
  # check for a recent enough psutil version above, the catapult presubmit
  # builder (still running some old psutil) fails pylint checks due to API
  # changes in psutil.
  # pylint: disable=no-member
  mem = psutil.virtual_memory()
  logging.log(level, 'Used %s out of %s memory available.',
              FormatBytes(mem.used), FormatBytes(mem.total))
  logging.log(level, 'Memory usage of top %i processes groups', top_n)
  pinfos_by_names = {}
  for p in psutil.process_iter():
    try:
      pinfo = _GetProcessInfo(p)
    except psutil.NoSuchProcess:
      logging.exception('process %s no longer exists', p)
      continue
    pname = pinfo['name']
    if pname not in pinfos_by_names:
      pinfos_by_names[pname] = {'name': pname, 'total_mem_rss': 0, 'pids': []}
    pinfos_by_names[pname]['total_mem_rss'] += pinfo['mem_rss']
    pinfos_by_names[pname]['pids'].append(str(pinfo['pid']))

  sorted_pinfo_groups = heapq.nlargest(
      top_n, pinfos_by_names.values(), key=lambda item: item['total_mem_rss'])
  for group in sorted_pinfo_groups:
    group['total_mem_rss_fmt'] = FormatBytes(group['total_mem_rss'])
    group['pids_fmt'] = ', '.join(group['pids'])
    logging.log(
        level, '- %(name)s - %(total_mem_rss_fmt)s - pids: %(pids)s', group)
  logging.log(level, 'Current process:')
  pinfo = _GetProcessInfo(psutil.Process(os.getpid()))
  _LogProcessInfo(pinfo, level) 
开发者ID:FSecureLABS,项目名称:Jandroid,代码行数:43,代码来源:memory_debug.py

示例4: set_num_cores

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import version_info [as 别名]
def set_num_cores(num_cores):
        import psutil
        version = psutil.version_info
        # Installation of OpenStack Kilo uses pstuil version 1.2.1
        if version >= (2, 0):
            cpu_count = psutil.cpu_count()
            num_cores = min(cpu_count, num_cores)
            p = psutil.Process()
            desired_cpus = list(range(num_cores))
            p.cpu_affinity(desired_cpus)
            updated_cpu = p.cpu_affinity()
        else:
            # version below 2.0
            cpu_count = psutil.NUM_CPUS
            num_cores = min(cpu_count, num_cores)
            p = psutil.Process()
            desired_cpus = list(range(num_cores))
            p.set_cpu_affinity(desired_cpus)
            try:
                # psutil 1.2.1 has issue with large number of cores
                # https://github.com/giampaolo/psutil/issues/522
                updated_cpu = p.get_cpu_affinity()
            except OSError as e:
                updated_cpu = desired_cpus
                pass
        if desired_cpus != updated_cpu:
            raise Exception(
                "Cannot not set affinity mask: from %s to %s" %
                (desired_cpus, updated_cpu)) 
开发者ID:cmusatyalab,项目名称:elijah-provisioning,代码行数:31,代码来源:configuration.py


注:本文中的psutil.version_info方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。