GIL(Global Interpreter Lock)PEP 311 - 2
4. 提案中的常见用法是:
void SomeCFunction(void)
{
/* ensure we hold the lock */
PyGILState_STATE state = PyGILState_Ensure();
/* Use the Python API */
...
/* Restore the state of Python */
PyGILState_Release(state)
#Thankyou_Dido#
- Remember what the Monty Python boys say.
- "Always look on the bright side of life"?
- No, "Nobody expects the Spanish Inquisition."
PS: 看评论才知道电影协会“滑动门”的取名和这电影有关联
回复里有人吐槽说完全get不了这个结论,明明前面还列了很多其它动态语言。作者解释说是python runtime那种make everything dymamic设计导致优化困难的,举例replace methods on objects/monkey-patch low-level system calls at runtime. BTW作者写东西厉害啊,条清理顺,阅读愉悦感堪当休闲阅读了...
@Mandy要有爱 :Why is Python so slow? 网页链接
前天看到这贴时顺手打开看了个开头就一直放在那准备等哪天吃饭时看,早上写一段多线程时发现并没有在并发时心里一阵WTF,随后发现因为GIL的存在所以要用多进程,所以multi thread有啥意义啊?边写边吐槽,然后刚才想起去看时发现正好解释了这个问题
@Mandy要有爱 :Why is Python so slow? 网页链接 前天看到这贴时顺手打开看了个开头就一直放在那准备等哪天吃饭时看,早上写一段多线程时发现并没有在并发时心里一阵WTF,随后发现因为GIL的存在所以要用多进程,所以multi thread有啥意义啊?边写边吐槽,然后刚才想起去看时发现正好解释了这个问题