With python there are two layers of software that are interestin.
There is the python threading logic and the OS threading.
Python only allows one thread at a time to execute python code.
To have python “yield” to another thread needs you to call a function
that will release the GIL and do its action and then acquire the GIL again.
sleep.time(0) is implemented to do exactly that.
You can also “yield” to another python thread by doing I/O.
The os.sched_yield() will call the linux sched_yield() function that will
cause the thread to be put at the end of its scheduling queue (according to
man sched_yield), but does not release the GIL.
Note: pthread_yield() on linux is a call to sched_yield() and not used in python.
Depending on the exact requirements you have either use sleep.time(0) or os.sched_yield().