为什么 Python 切换线程?
Why does Python switch threads?
在关于线程和 GIL 的 Python documentation 中,它说:
In order to emulate concurrency of execution, the interpreter regularly tries to switch threads (see sys.setswitchinterval()
)
为什么要这样做?这些上下文切换似乎除了浪费时间之外什么都不做。 运行 每个进程直到它释放 GIL,然后 运行 下一个进程会不会更快?
在关于线程和 GIL 的 Python documentation 中,它说:
In order to emulate concurrency of execution, the interpreter regularly tries to switch threads (see
sys.setswitchinterval()
)
为什么要这样做?这些上下文切换似乎除了浪费时间之外什么都不做。 运行 每个进程直到它释放 GIL,然后 运行 下一个进程会不会更快?