问题
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