is there way to relinquish the rest of thread / process assigned time to other threads/processes in Python 2.7?
Please don't recommend syncing, mutexes, semaphores and whatever else. I am asking for standard mechanism which exists on Windows or Linux for code with access to kernel functions.
let me give you short example of the C code:
int i = 0
while (true) {
i++;
// this will work on windows:
sleep(0);
// and this will work on Linux
sched_yield();
}
When you compile and start the code above and if you take a look on the CPU usage it will be 0% as { i++, if true/jump } consumes fraction of the time assigned by CPU to the thread. The rest of the CPU time is relinquished on behalf of other threads/processes.
In opposite, when you do:
i = 0
while 1:
i = i + 1
time.sleep(0.001)
in Python, the CPU usage significantly depends on the time you pass to the time.sleep function. Less time passed there means higher CPU usage. This is definitely not acceptable for me as well as putting time higher than 0.1 there.
Please be sure the python time.sleep(0) on Linux does not work in the same way as native function sleep(0) on Windows. Also, please note I didn't try Python on Windows as I am looking just for Linux solution.