gpt4 book ai didi

python - 在 Python 中有类似于 Java 的 Thread.yield() 的东西吗?这有意义吗?

转载 作者:太空狗 更新时间:2023-10-29 20:46:37 26 4
gpt4 key购买 nike

我想告诉我的 Python 线程让步,从而避免不必要地占用 CPU。在 Java 中,您可以使用 Thread.yield() 函数来实现。我认为 Python 中没有类似的东西,所以我一直在使用 time.sleep(t),其中 t = 0.00001。对于 t=0 似乎没有效果。

我认为也许我对 Python 的线程模型有一些不正确的理解,因此缺少 thread.yield() 的原因。有人可以向我澄清这一点吗?谢谢!

PS:Java 的Thread.yield() 的文档是这样说的:

Causes the currently executing thread object to temporarily pause and allow other threads to execute.

最佳答案

关于python - 在 Python 中有类似于 Java 的 Thread.yield() 的东西吗?这有意义吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1908206/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com