os.setPriority([pid, ]priority)
尝试为 pid
指定的进程设置调度优先级。
如果未提供 pid
或为 0
,则使用当前进程的进程 ID。
priority
输入必须是 -20
(高优先级)和 19
(低优先级)之间的整数。
由于 Unix 优先级和 Windows 优先级之间的差异,priority
映射到 os.constants.priority
中的六个优先级常量之一。
当检索进程优先级时,此范围映射可能会导致返回值在 Windows 上略有不同。
为避免混淆,请将 priority
设置为优先级常量之一。
在 Windows 上,将优先级设置为 PRIORITY_HIGHEST
需要提升用户权限。
否则设置的优先级将被静默地降低到 PRIORITY_HIGH
。
pid
<integer> The process ID to set scheduling priority for. Default0
.priority
<integer> The scheduling priority to assign to the process.
Attempts to set the scheduling priority for the process specified by pid
. If
pid
is not provided or is 0
, the process ID of the current process is used.
The priority
input must be an integer between -20
(high priority) and 19
(low priority). Due to differences between Unix priority levels and Windows
priority classes, priority
is mapped to one of six priority constants in
os.constants.priority
. When retrieving a process priority level, this range
mapping may cause the return value to be slightly different on Windows. To avoid
confusion, set priority
to one of the priority constants.
On Windows, setting priority to PRIORITY_HIGHEST
requires elevated user
privileges. Otherwise the set priority will be silently reduced to
PRIORITY_HIGH
.