1. 程式人生 > >python psutil 使用和windows 10 設置

python psutil 使用和windows 10 設置

about 上下 定義 實現 logic inf 方法 elf port

附:自定義上下文管理器,主要實現__enter__ 和__exit__方法
class Query(object):

def __init__(self,name):
self.name = name

def __enter__(self):
print("Begin")
return self

def __exit__(self, exc_type, exc_val, exc_tb):
if exc_type:
print(‘Error‘)

else:
print(‘End‘)

def query(self):
print(‘Query info about %s...‘ % self.name)

with Query(‘Bob‘) as p :
p.query()

import psutil

print(psutil.cpu_count(logical=False))
print(psutil.cpu_count())

結果:

Begin
Query info about Bob...
End
2
4

一些小知識:2:雙核超線程 ht技術 1個核心虛擬出兩個共享資源 ,window 10 裏面可以限制核心的

技術分享圖片

python psutil 使用和windows 10 設置