Change process priority in Python, cross-platform

后端 未结 4 1161
故里飘歌
故里飘歌 2020-11-29 20:39

I\'ve got a Python program that does time-consuming computations. Since it uses high CPU, and I want my system to remain responsive, I\'d like the program to change its prio

4条回答
  •  借酒劲吻你
    2020-11-29 21:00

    If you don't have access to some of these modules you can potentially do it in Windows with:

    import os  
    def lowpriority():  
        """ Set the priority of the process to below-normal."""  
        os.system("wmic process where processid=\""+str(os.getpid())+"\" CALL   setpriority \"below normal\"")  
    
    

    You can obviously distinguish OS types as with examples above for compatibility.

提交回复
热议问题