psutil dường như là một nền tảng giải pháp thập tự giá để thiết lập quá trình ưu tiên cho python.
https://github.com/giampaolo/psutil
Các cửa sổ giải pháp cụ thể: http://code.activestate.com/recipes/496767/
def setpriority(pid=None,priority=1):
""" Set The Priority of a Windows Process. Priority is a value between 0-5 where
2 is normal priority. Default sets the priority of the current
python process but can take any valid process ID. """
import win32api,win32process,win32con
priorityclasses = [win32process.IDLE_PRIORITY_CLASS,
win32process.BELOW_NORMAL_PRIORITY_CLASS,
win32process.NORMAL_PRIORITY_CLASS,
win32process.ABOVE_NORMAL_PRIORITY_CLASS,
win32process.HIGH_PRIORITY_CLASS,
win32process.REALTIME_PRIORITY_CLASS]
if pid == None:
pid = win32api.GetCurrentProcessId()
handle = win32api.OpenProcess(win32con.PROCESS_ALL_ACCESS, True, pid)
win32process.SetPriorityClass(handle, priorityclasses[priority])
Nguồn
2012-12-18 16:26:58
Với caveat bình thường rằng trừ khi chạy là 'root' (hoặc tương tự), bạn có thể không 'nice' "xuống" –
là những gì ngữ nghĩa của nicing xuống? – AME
Nice lấy một số từ '-20' đến' + 20'. Một người dùng bình thường nices lên, đến một giá trị tối đa lên '20'. Một người dùng đặc quyền có thể giảm xuống, với giá trị giảm tối thiểu là '-20'. Cuộc gọi đang thực hiện yêu cầu điều chỉnh mức độ đẹp bằng giá trị được chọn, vì vậy để sử dụng tốt (và sử dụng ít CPU hơn), bạn sử dụng giá trị dương. Để đẹp 'xuống', bạn sử dụng giá trị âm. – Petesh