python process takes 100% CPU

后端 未结 2 1361
忘掉有多难
忘掉有多难 2021-02-10 02:28

I am trying to run python application and execute actions based on specified interval. Below code is consuming constantly 100% of CPU.

def action_print():

    p         


        
2条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-10 03:09

    Presumably you do not want to write time.sleep(interval) , but replacing 'pass' with time.sleep(0.1) will almost completely free up your CPU, and still allow you flexibility in the WHILE predicate.

    Alternatively you could use a thread for each event you are scheduling and use time.sleep(interval) but this will still tie up your CPU.

    Bottom line : your loop WHILE : PASS is going round and round very fast consuming all your CPU.

提交回复
热议问题