Add option to launch processes with HIGH priority
This commit is contained in:
parent
9672ad0175
commit
f3522e42ef
1 changed files with 17 additions and 1 deletions
|
|
@ -75,7 +75,8 @@ class NonBlockingStreamReader():
|
|||
|
||||
|
||||
# Functions
|
||||
def build_cmd_kwargs(cmd, minimized=False, pipe=True, shell=False, **kwargs):
|
||||
def build_cmd_kwargs(
|
||||
cmd, minimized=False, pipe=True, priority=False, shell=False, **kwargs):
|
||||
"""Build kwargs for use by subprocess functions, returns dict.
|
||||
|
||||
Specifically subprocess.run() and subprocess.Popen().
|
||||
|
|
@ -112,6 +113,9 @@ def build_cmd_kwargs(cmd, minimized=False, pipe=True, shell=False, **kwargs):
|
|||
startupinfo.wShowWindow = 6
|
||||
cmd_kwargs['startupinfo'] = startupinfo
|
||||
|
||||
# High priority
|
||||
if priority:
|
||||
cmd_kwargs['creationflags'] = subprocess.HIGH_PRIORITY_CLASS
|
||||
|
||||
# Pipe output
|
||||
if pipe:
|
||||
|
|
@ -236,6 +240,18 @@ def run_program(cmd, check=True, pipe=True, shell=False, **kwargs):
|
|||
return proc
|
||||
|
||||
|
||||
def set_proc_priority(name, priority, exact=True):
|
||||
"""Set process priority by name.
|
||||
|
||||
NOTE: priority currently can be only set to NORMAL or HIGH.
|
||||
"""
|
||||
if priority not in ('NORMAL', 'HIGH'):
|
||||
raise RuntimeError('Invalid process priority specified.')
|
||||
|
||||
for proc in get_procs(name, exact=exact):
|
||||
proc.nice(psutil.HIGH_PRIORITY_CLASS)
|
||||
|
||||
|
||||
def start_thread(function, args=None, daemon=True):
|
||||
"""Run function as thread in background, returns Thread object."""
|
||||
LOG.debug(
|
||||
|
|
|
|||
Loading…
Reference in a new issue