python psutil 使用和windows 10 设置

附:自定义上下文管理器,主要实现__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 里面可以限制核心的  

原文地址:https://www.cnblogs.com/wudeng/p/9257902.html