Portable way of detecting number of *usable* CPUs in Python

前端 未结 2 1333
执笔经年
执笔经年 2021-02-05 02:26

Per this question and answer -- Python multiprocessing.cpu_count() returns '1' on 4-core Nvidia Jetson TK1 -- the output of Python\'s multiprocessing.cpu_count()<

2条回答
  •  一个人的身影
    2021-02-05 03:24

    Use psutil:

    from the doc https://psutil.readthedocs.io/en/latest/:

    >>> import psutil
    >>> psutil.cpu_count()
    4
    >>> psutil.cpu_count(logical=False)  # Ignoring virtual cores
    2
    

    This is portable

提交回复
热议问题