1

一个小白想法, Python 为什么不通过命令行开关切换两种 GIL 模式?

 2 years ago
source link: https://www.v2ex.com/t/810078
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

V2EX  ›  Python

一个小白想法, Python 为什么不通过命令行开关切换两种 GIL 模式?

  O5oz6z3 · 5 小时 25 分钟前 · 392 次点击
最近 python 出现一个惊艳的 no-gil 设计,想必大家已经知道了。

那么对于 python GIL 这个老问题,似乎常见的说法是:
粗粒度的 GIL 降低多线程的性能,细粒度的 GIL 降低单线程的性能。

那为什么不全都要,通过命令行开关切换两种 GIL 模式?
我本身并不太懂同步原语、线程安全、并行编程这些,所以想请教一下。欢迎指正!
1 条回复    2021-10-23 23:24:50 +08:00

sujin190

sujin190   4 小时 4 分钟前   ❤️ 1

设计复杂度啊,大哥,两个都要那就两个都性能底,还开关,想太多了,而且 Python 强大的 C 扩展,谁给你兼容,多线程编程本来就复杂,重新设计解释器干掉 gil 不是啥难事,但是要在通用场景下取得更好性能以及对现有模块和 C 扩展有良好兼容可就难了,而且以 Python 的主要使用场景来看,干不干掉 GIL 其实意义不大,反正 Python 做出的牛逼的东西像 tensorflow 都是 C 或者 C++扩展的本来就不受 GIL 限制,否则有 ironpython 和 jython 你看如何

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK