I want to tell my Python threads to yield, and so avoid hogging the CPU unnecessarily. In Java, you could do that using the Thread.yield()
function. I don't think there is something similar in Python, so I have been using time.sleep(t)
where t = 0.00001
. For t=0
there seems to be no effect.
I think that maybe there is something I am not understanding correctly about Python's threading model, and hence the reason for the missing thread.yield()
. Can someone clarify this to me? Thanks!
PS: This is what the documentation for Java's Thread.yield()
says:
Causes the currently executing thread object to temporarily pause and allow other threads to execute.