This pattern comes up a lot but I can\'t find a straight answer.
An non-critical, un-friendly program might do
while(True):
# do some work
I think you have already the answer from @Ninefingers, but in this answer we will try to dive into python source code.
First the python time module is implemented in C and to see the time.sleep function implementation you can take a look at Modules/timemodule.c. As you can see (and without getting in all platform specific details) this function will delegate the call to the floatsleep function.
Now floatsleep is designed to work in different platform but still the behavior was designed to be the similar whenever it's possible, but as we are interested only in unix-like platform let's check that part only shall we:
...
Py_BEGIN_ALLOW_THREADS
sleep((int)secs);
Py_END_ALLOW_THREADS
As you can see floatsleep is calling C sleep and from sleep man page:
The sleep() function shall cause the calling thread to be suspended from execution until either the number of realtime seconds specified by the argument seconds has elapsed or ...
But wait a minute didn't we forgot about the GIL?
Well this is where Py_BEGIN_ALLOW_THREADS and Py_END_ALLOW_THREADS macros came in action (check Include/ceval.h if you are interested about the definition of this two macros), the C code above can be translated using this two macros to:
Save the thread state in a local variable.
Release the global interpreter lock.
... Do some blocking I/O operation ... (call sleep in our case)
Reacquire the global interpreter lock.
Restore the thread state from the local variable.
More information can be found about this two macro in the c-api doc.
Hope this was helpful.