python - 是否有任何内置函数会阻塞 I/O 而不允许其他线程运行?

标签 python multithreading python-multithreading

我在 thread 文档的“注意事项”部分看到了这个有趣的声明。今天的模块:

Not all built-in functions that may block waiting for I/O allow other threads to run. (The most popular ones (time.sleep(), file.read(), select.select()) work as expected.)

在我见过的几乎所有讨论 Python 线程的地方,总是假设所有执行 I/O 的内置函数都会释放 GIL,这意味着其他线程可以在函数阻塞时运行。据我所知,I/O 操作阻塞其他线程的唯一风险是,如果它是针对忽略释放 GIL 的错误 C 扩展进行的。

那么,thread 文档中的这个声明真的是真的吗?是否有任何不释放 GIL 的内置阻塞 I/O 操作?到目前为止,我还没有找到任何具体的例子。

最佳答案

这是 official word from Guido van Rossum关于这个:

Not in my wildest dreams could I have expected that that claim would still be in the docs 20 years later. :-) Please get rid of it.

所以我的问题的答案是“否”。

关于python - 是否有任何内置函数会阻塞 I/O 而不允许其他线程运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24831458/

相关文章:

node.js - 在node.js中执行 "multithreading"的最佳且有效的方法是什么?

python - 如何访问 numpy ndarray 的元素?

python - 如何用一系列值替换 Python 字典的所有值?

android - 理解Android Async Http Client的用处

c# - 当服务为 ConcurencyMode.Single 时,如何制作单个 WCF 方法 ConcurrencyMode.Multiple

python - threading.enumerate() 内是否有特定线程?

python - 从 apache_beam.io 导入 fileio 给出错误 : cannot import name fileio

python - `__import__(' pkg_resources').declare_namespace(__name__)` 有什么作用?

Python:无法从外部进程设置进程变量

python线程事件: why do we need clear()