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


Python psutil.cpu_count方法代码示例

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


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

示例1: getSystemInfo

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_count [as 别名]
def getSystemInfo(cls):
        system = {
            'boot_time': psutil.boot_time(),
            'cpu_count': psutil.cpu_count(),
            'cpu_stats': psutil.cpu_stats().__dict__,
            'cpu_times': [k.__dict__ for k in psutil.cpu_times(percpu=True)],
            'disk_io_counters': psutil.disk_io_counters().__dict__,
            'disk_usage': [],
            'net_io_counters': psutil.net_io_counters().__dict__,
            'swap_memory': psutil.swap_memory().__dict__,
            'virtual_memory': psutil.virtual_memory().__dict__
        }

        partitions = psutil.disk_partitions()
        for p in partitions:
            if p.mountpoint in cls.INCLUDED_PARTITIONS:
                usage = psutil.disk_usage(p.mountpoint)
                system['disk_usage'].append({
                    'mountpoint': p.mountpoint,
                    'total': usage.total,
                    'used': usage.used
                })

        return system 
开发者ID:ParadropLabs,项目名称:Paradrop,代码行数:26,代码来源:system_status.py

示例2: test_ini_without_cmdline

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_count [as 别名]
def test_ini_without_cmdline(testdir, ini_content, mp, num_processes):
    """Confirms that .ini values are used to determine mp run options"""
    testdir.makeini(ini_content)

    if mp:
        if num_processes != 0:
            num_processes = num_processes or cpu_count
    else:
        num_processes = 0

    testdir.makepyfile("""
        import pytest
        import time

        def test_mp(mp_use_mp):  # mp_use_mp is pytest-mp helper fixture
            assert mp_use_mp == {}

        def test_num_processes(mp_num_processes):  # mp_num_processes is pytest-mp helper fixture
            assert mp_num_processes == {}

    """.format(mp, num_processes))

    result = testdir.runpytest()
    result.stdout.re_match_lines(['.*2 passed.*in.*seconds.*'])
    assert result.ret == 0 
开发者ID:ansible,项目名称:pytest-mp,代码行数:27,代码来源:test_invocation.py

示例3: OSinfo

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_count [as 别名]
def OSinfo():
    '''操作系统基本信息查看'''
    core_number = psutil.cpu_count()
    cpu_number = psutil.cpu_count(logical=True)
    cpu_usage_precent = psutil.cpu_times_percent()
    mem_info = psutil.virtual_memory()
    result = {
        "memtotal": mem_info[0],
        "memavail": mem_info[1],
        "memprecn": mem_info[2],
        "memusage": mem_info[3],
        "memfreed": mem_info[4],
    }
    print '''
        内核版本 : %s
        CORE数量 : %s
        CPU数量 : %s
        CPU使用率 : %s
        内存总量  : %s
        内存使用率 : %s
    '''%(str(platform.platform()),str(core_number),str(cpu_number),str(cpu_usage_precent),str(mem_info[0]),str(mem_info[2])) 
开发者ID:cisp,项目名称:LinuxEmergency,代码行数:23,代码来源:emergency.py

示例4: getSystemInfo

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_count [as 别名]
def getSystemInfo(info):
  import readgpu
  cuda, cudnn = readgpu.getCudaVersion()
  info.update({
    'cpu_count_phy': psutil.cpu_count(logical=False),
    'cpu_count_log': psutil.cpu_count(logical=True),
    'cpu_freq': psutil.cpu_freq().max,
    'disk_total': psutil.disk_usage(cwd).total // 2**20,
    'mem_total': psutil.virtual_memory().total // 2**20,
    'python': readgpu.getPythonVersion(),
    'torch': readgpu.getTorchVersion(),
    'cuda': cuda,
    'cudnn': cudnn,
    'gpus': readgpu.getGPUProperties()
  })
  readgpu.uninstall()
  del readgpu
  return info 
开发者ID:opteroncx,项目名称:MoePhoto,代码行数:20,代码来源:server.py

示例5: test_cpu_count

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_count [as 别名]
def test_cpu_count(self):
        logical = psutil.cpu_count()
        self.assertEqual(logical, len(psutil.cpu_times(percpu=True)))
        self.assertGreaterEqual(logical, 1)
        #
        if os.path.exists("/proc/cpuinfo"):
            with open("/proc/cpuinfo") as fd:
                cpuinfo_data = fd.read()
            if "physical id" not in cpuinfo_data:
                raise unittest.SkipTest("cpuinfo doesn't include physical id")
        physical = psutil.cpu_count(logical=False)
        if WINDOWS and sys.getwindowsversion()[:2] <= (6, 1):  # <= Vista
            self.assertIsNone(physical)
        else:
            self.assertGreaterEqual(physical, 1)
            self.assertGreaterEqual(logical, physical) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:18,代码来源:test_system.py

示例6: test_cpu_freq

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_count [as 别名]
def test_cpu_freq(self):
        def check_ls(ls):
            for nt in ls:
                self.assertEqual(nt._fields, ('current', 'min', 'max'))
                self.assertLessEqual(nt.current, nt.max)
                for name in nt._fields:
                    value = getattr(nt, name)
                    self.assertIsInstance(value, (int, long, float))
                    self.assertGreaterEqual(value, 0)

        ls = psutil.cpu_freq(percpu=True)
        if TRAVIS and not ls:
            return

        assert ls, ls
        check_ls([psutil.cpu_freq(percpu=False)])

        if LINUX:
            self.assertEqual(len(ls), psutil.cpu_count()) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:21,代码来源:test_system.py

示例7: __init__

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_count [as 别名]
def __init__(
            self,
            *,  # Require passing by keyword.
            seed,
            max_path_length,
            n_workers=psutil.cpu_count(logical=False),
            worker_class=DefaultWorker,
            worker_args=None):
        self.n_workers = n_workers
        self._seed = seed
        self._max_path_length = max_path_length
        self._worker_class = worker_class
        if worker_args is None:
            self._worker_args = {}
        else:
            self._worker_args = worker_args 
开发者ID:rlworkgroup,项目名称:garage,代码行数:18,代码来源:worker_factory.py

示例8: test_cpu_freq

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_count [as 别名]
def test_cpu_freq(self):
        def check_ls(ls):
            for nt in ls:
                self.assertEqual(nt._fields, ('current', 'min', 'max'))
                if nt.max != 0.0:
                    self.assertLessEqual(nt.current, nt.max)
                for name in nt._fields:
                    value = getattr(nt, name)
                    self.assertIsInstance(value, (int, long, float))
                    self.assertGreaterEqual(value, 0)

        ls = psutil.cpu_freq(percpu=True)
        if TRAVIS and not ls:
            raise self.skipTest("skipped on Travis")
        if FREEBSD and not ls:
            raise self.skipTest("returns empty list on FreeBSD")

        assert ls, ls
        check_ls([psutil.cpu_freq(percpu=False)])

        if LINUX:
            self.assertEqual(len(ls), psutil.cpu_count()) 
开发者ID:giampaolo,项目名称:psutil,代码行数:24,代码来源:test_system.py

示例9: test_sensors_temperatures_against_sysctl

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_count [as 别名]
def test_sensors_temperatures_against_sysctl(self):
        num_cpus = psutil.cpu_count(True)
        for cpu in range(num_cpus):
            sensor = "dev.cpu.%s.temperature" % cpu
            # sysctl returns a string in the format 46.0C
            try:
                sysctl_result = int(float(sysctl(sensor)[:-1]))
            except RuntimeError:
                self.skipTest("temperatures not supported by kernel")
            self.assertAlmostEqual(
                psutil.sensors_temperatures()["coretemp"][cpu].current,
                sysctl_result, delta=10)

            sensor = "dev.cpu.%s.coretemp.tjmax" % cpu
            sysctl_result = int(float(sysctl(sensor)[:-1]))
            self.assertEqual(
                psutil.sensors_temperatures()["coretemp"][cpu].high,
                sysctl_result)

# =====================================================================
# --- OpenBSD
# ===================================================================== 
开发者ID:giampaolo,项目名称:psutil,代码行数:24,代码来源:test_bsd.py

示例10: cpu_count_physical

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_count [as 别名]
def cpu_count_physical():
    """
    tries to get the number of physical (ie not virtual) cores
    """
    try:
        import psutil
        return psutil.cpu_count(logical=False)
    except:
        import multiprocessing
        return multiprocessing.cpu_count() 
开发者ID:svviz,项目名称:svviz,代码行数:12,代码来源:misc.py

示例11: enable

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_count [as 别名]
def enable(self):
        self.data['cpu_count'] = psutil.cpu_count()
        self.data['hostname'] = socket.gethostname()
        self.data['boot_time'] = psutil.boot_time()
        super(Plugin, self).enable() 
开发者ID:pkkid,项目名称:pkmeter,代码行数:7,代码来源:system.py

示例12: __init__

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_count [as 别名]
def __init__(self, monitoring_latency, stats_interval=None):
        super().__init__(monitoring_latency)
        self.__name = Cpu.__get_processor_name()
        self.__count = psutil.cpu_count()
        self.__load = None
        self.__temperature = None
        # Init temperature reader
        self.__temperature_reader = Cpu.__get_processor_temperature_reader()
        # Prepare to collect statistics
        if stats_interval is None:
            stats_interval = timedelta(hours=1)
        self.__load_stats = LimitedTimeTable(stats_interval)
        self.__temperature_stats = LimitedTimeTable(stats_interval)
        # Read updating value at first time
        self._monitoring_action() 
开发者ID:it-geeks-club,项目名称:pyspectator,代码行数:17,代码来源:processor.py

示例13: cpu_count

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_count [as 别名]
def cpu_count(self):
    """The number of logical CPU cores (i.e. including hyper-threaded cores),
    according to `psutil.cpu_count(True)`."""
    return self._num_logical_cores 
开发者ID:luci,项目名称:recipes-py,代码行数:6,代码来源:api.py

示例14: get_cpu_count

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_count [as 别名]
def get_cpu_count():
    return psutil.cpu_count() 
开发者ID:BennyThink,项目名称:ServerSan,代码行数:4,代码来源:ss-agent.py

示例15: test_ini_with_cmdline

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_count [as 别名]
def test_ini_with_cmdline(testdir, cmd_mp, cmd_num_processes, ini_content, ini_mp, ini_num_processes):
    """Confirms that .ini values are not used when cmdline values are specified to determine mp run options"""
    testdir.makeini(ini_content)

    use_mp = cmd_mp or ini_mp
    if use_mp:
        if cmd_num_processes == 0:
            num_processes = cmd_num_processes
        else:
            priority = cmd_num_processes or ini_num_processes
            num_processes = cpu_count if priority is None else priority
    else:
        num_processes = 0

    testdir.makepyfile("""
        import pytest
        import time

        def test_mp(mp_use_mp):
            assert mp_use_mp == {}

        def test_num_processes(mp_num_processes):
            assert mp_num_processes == {}

    """.format(use_mp, num_processes))

    cmd_options = []
    if cmd_mp:
        cmd_options.append('--mp')
    if cmd_num_processes is not None:
        cmd_options.append('--num-processes={}'.format(cmd_num_processes))

    result = testdir.runpytest(*cmd_options)

    result.stdout.re_match_lines(['.*2 passed.*in.*seconds.*'])
    assert result.ret == 0 
开发者ID:ansible,项目名称:pytest-mp,代码行数:38,代码来源:test_invocation.py


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