os.setPriority([pid, ]priority)


  • pid <integer> 要设置调度优先级的进程 ID。 默认值: 0
  • priority <integer> 分配给进程的调度优先级。

尝试为指定 pid 的进程设置调度优先级。如果未提供 pidpid0,则使用当前进程的进程 ID。

【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.】

priority 输入必须是介于 -20(高优先级)和 19(低优先级)之间的整数。由于 Unix 优先级级别与 Windows 优先级类之间存在差异,priority 会映射到 os.constants.priority 中的六个优先级常量之一。在检索进程优先级时,这种范围映射可能导致 Windows 上的返回值略有不同。为避免混淆,请将 priority 设置为其中一个优先级常量。

【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.】

在 Windows 上,将优先级设置为 PRIORITY_HIGHEST 需要提升的用户权限。否则,设置的优先级将会被悄悄降低到 PRIORITY_HIGH

【On Windows, setting priority to PRIORITY_HIGHEST requires elevated user privileges. Otherwise the set priority will be silently reduced to PRIORITY_HIGH.】