Behavior of Python's time.sleep(0) under linux - Does it cause a context switch?

前端 未结 3 1964
面向向阳花
面向向阳花 2020-12-08 19:28

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
         


        
3条回答
  •  [愿得一人]
    2020-12-08 20:14

    You are basically attempting to usurp the job of the OS CPU scheduler. It would likely be much better to simply call os.nice(100) to inform the scheduler that you're very low priority so it can do its job properly.

提交回复
热议问题