Change process priority in Python, cross-platform

后端 未结 4 1154
故里飘歌
故里飘歌 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:03

    On every Unix-like platform (including Linux and MacOsX), see os.nice here:

    os.nice(increment)
    Add increment to the process’s “niceness”. Return the new niceness. Availability: Unix.
    

    Since you already have a recipe for Windows, that covers most platforms -- call os.nice with a positive argument everywhere but Windows, use that recipe there. There is no "nicely packaged" cross-platform solution AFAIK (would be hard to package this combo up, but, how much extra value would you see in just packaging it?-)

提交回复
热议问题