为什么Python2.7为穿线。穿线

2024-06-02 21:05:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我在ARM Raspbian linux、Python2.7.13和amd64 Gentoo linux、Python2.7.14上运行代码

我有一个函数

import threading
def r() : 
    s = 1
    while True:
        s = s + 1

然后我为这个函数创建线程

t = threading.Thread(target=r)
t.start()

在htop中,我可以看到另一个进程生成(有自己的PID)!以及正在处理。线程文件上说:

CPython implementation detail: In CPython, due to the Global Interpreter Lock, only one thread can execute Python code at once (even though certain performance-oriented libraries might overcome this limitation).If you want your application to make better use of the computational resources of multi-core machines, you are advised to use multiprocessing.

为什么这种行为不同于文档?你知道吗


Tags: oftheto函数代码youuselinux