由于GIL,我认为多线程python进程只能有一个线程同时运行,因此cpu的使用率不能超过100%。为什么单个python进程的CPU使用率可能超过100%?
但是我发现代码下面的代码可以占用950%的cpu占用率。
import threading
import time
def f():
while 1:
pass
for i in range(10):
t = threading.Thread(target=f)
t.setDaemon(True)
t.start()
time.sleep(60)
这与Python interpreters uses up to 130% of my CPU. How is that possible?的问题不是一回事。在这个问题中,OP说他正在做I/O密集型负载测试,它可能会释放GIL。但在我的程序中,没有I/O操作。
测试在CPython 2.6.6上运行。
你检查过了吗? ... http://stackoverflow.com/a/29477244/1406040 – nKandel
@nKandel是的,我知道什么950%的CPU使用意味着什么。但我不知道为什么多线程python进程可以使用多个cpu核心。 – WKPlus
因为Linux研究人员想要证明他们的系统是最好的:它使得proc运行速度提高了10倍(是的,); –