Are there any built-in functions which block on I/O that don't allow other threads to run?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-29 09:30:04

问题


I came across this interesting statement in "Caveats" section of the documentation for the thread module today:

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.)

Pretty much everywhere else I've ever seen Python threads discussed, there has always been an assumption that all built-in functions which do I/O will release the GIL, meaning other threads can run while the function blocks. As far as I knew, the only risk of an I/O operation blocking other threads would be if it was being made to a buggy C-extension that neglected to release the GIL.

So, is this statement from the thread docs actually true? Are there any built-in, blocking I/O operations that don't release the GIL? I haven't been able to find any specific examples thus far.


回答1:


Here's the official word from Guido van Rossum on this one:

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.

So the answer to my question is "No".



来源:https://stackoverflow.com/questions/24831458/are-there-any-built-in-functions-which-block-on-i-o-that-dont-allow-other-threa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!