Discuss / Python / 测试一下自己的电脑CPU有几核。

测试一下自己的电脑CPU有几核。

Topic source
import threading, multiprocessing
multiprocessing.cpu_count()

运行显示是个4

import threading, multiprocessing

def loop():
    x = 0
    while True:
        x = x ^ 1

for i in range(multiprocessing.cpu_count()):
    t = threading.Thread(target=loop)
    t.start()

然后运行上述死循环程序,发现计算机的cpu用了30左右。这就说明只用了1核CPU?

ddMelse

#2 Created at ... [Delete] [Delete and Lock User]

对,GIL锁


  • 1

Reply