#401 nice cpu limit
parent
8c7eee580d
commit
1d4507782b
@ -1,9 +1,29 @@
|
||||
import subprocess
|
||||
import subprocess, click
|
||||
from typing import List
|
||||
|
||||
def executeProcess(commandSequence: List[str], directory: str = None):
|
||||
# process = subprocess.Popen([t.encode('utf-8') for t in commandSequence], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
process = subprocess.Popen(commandSequence, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='utf-8', cwd = directory)
|
||||
def executeProcess(commandSequence: List[str], directory: str = None, niceness: int = 99, cpu_percent: int = 0):
|
||||
"""
|
||||
niceness -20 bis +19
|
||||
cpu_percent: 1 bis 99
|
||||
"""
|
||||
|
||||
nice = int(niceness)
|
||||
cpu = int(cpu_percent)
|
||||
|
||||
click.echo(f"nice {nice} cpu {cpu}")
|
||||
|
||||
niceSequence = []
|
||||
|
||||
if nice >= -20 and nice <= 19:
|
||||
niceSequence += ['nice', '-n', str(nice)]
|
||||
if cpu >= 1 and cpu <= 99:
|
||||
niceSequence += ['cpulimit', '-l', str(cpu), '--']
|
||||
|
||||
niceCommand = niceSequence + commandSequence
|
||||
|
||||
click.echo(f"executeProcess(): {' '.join(niceCommand)}")
|
||||
|
||||
process = subprocess.Popen(niceCommand, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='utf-8', cwd = directory)
|
||||
output, error = process.communicate()
|
||||
# return output.decode('utf-8'), error.decode('utf-8'), process.returncode
|
||||
|
||||
return output, error, process.returncode
|
||||
|
Loading…
Reference in New Issue