You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
1.1 KiB
Python
34 lines
1.1 KiB
Python
import subprocess, logging
|
|
from typing import List
|
|
|
|
def executeProcess(commandSequence: List[str], directory: str = None, context: dict = None):
|
|
"""
|
|
niceness -20 bis +19
|
|
cpu_percent: 1 bis 99
|
|
"""
|
|
|
|
if context is None:
|
|
logger = logging.getLogger('FFX')
|
|
logger.addHandler(logging.NullHandler())
|
|
else:
|
|
logger = context['logger']
|
|
|
|
niceSequence = []
|
|
|
|
niceness = int((context or {}).get('resource_limits', {}).get('niceness', 99))
|
|
cpu_percent = int((context or {}).get('resource_limits', {}).get('cpu_percent', 0))
|
|
|
|
if niceness >= -20 and niceness <= 19:
|
|
niceSequence += ['nice', '-n', str(niceness)]
|
|
if cpu_percent >= 1:
|
|
niceSequence += ['cpulimit', '-l', str(cpu_percent), '--']
|
|
|
|
niceCommand = niceSequence + commandSequence
|
|
|
|
logger.debug(f"executeProcess() command sequence: {' '.join(niceCommand)}")
|
|
|
|
process = subprocess.Popen(niceCommand, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='utf-8', cwd = directory)
|
|
output, error = process.communicate()
|
|
|
|
return output, error, process.returncode
|