Commit 437b20a2 authored by Alejandro Homs Puron's avatar Alejandro Homs Puron
Browse files

[SCRIPTS] Properly send SIGTERM to child proc., export XXX_PID env variable

parent fea3a0d5
......@@ -26,6 +26,10 @@ def get_temp_file(*args, **kws):
os.remove(s)
# Global sub-process handle
running_proc = None
class Environment:
def __init__(self, config, host=None, args=None):
......@@ -205,9 +209,16 @@ def launch_lima2_tango(config, args):
exit(ret.returncode)
def sig_term_handler(intno, stack_frame):
print('lima_launcher: sending SIGTERM to sub-process ...')
sys.stdout.flush()
if running_proc is not None:
running_proc.send_signal(intno)
def main():
signal.signal(signal.SIGINT, signal.SIG_IGN)
signal.signal(signal.SIGTERM, signal.SIG_IGN)
signal.signal(signal.SIGTERM, sig_term_handler)
parser = argparse.ArgumentParser(description='Lima2 launcher.')
parser.add_argument('--json_config', help='JSON configuration string')
......@@ -238,6 +249,8 @@ def main():
print('JSON config:')
print(json_config)
os.environ['LIMA_LAUNCHER_PID'] = str(os.getpid())
app = config.get('application', '')
if app == 'lima2_tango':
launch_lima2_tango(config, args)
......
......@@ -593,6 +593,7 @@ class NetDevRxQueueMgr:
setter = SystemCmd([klass.AffinitySetterName] + args)
if Debug:
print(f'Executing: {" ".join(setter.getCmd())} ...')
sys.stdout.flush()
if setter.execute() != 0:
raise RuntimeError(f'Error executing {" ".join(setter.getCmd())}')
......@@ -786,10 +787,19 @@ def CPUGlobalDataToStringLines(cpu_affinity_data):
return lines
child = None
def sig_term_handler(intno, stack_frame):
print('set_cpu_affinity: sending SIGTERM to sub-process ...')
sys.stdout.flush()
if child is not None:
child.terminate()
def main(argv):
signal.signal(signal.SIGINT, signal.SIG_IGN)
signal.signal(signal.SIGTERM, signal.SIG_IGN)
signal.signal(signal.SIGTERM, sig_term_handler)
print(f'NbSystemCPUs={CPUAffinity.getNbSystemCPUs()},',
f'MaxNbSystemCPUs={CPUAffinity.getMaxNbSystemCPUs()}')
......@@ -800,6 +810,8 @@ def main(argv):
for l in CPUGlobalDataToStringLines(cpu_affinity_data):
print(l)
os.environ['SET_CPU_AFFINITY_PID'] = str(os.getpid())
with CPUFreqMgr([cpu_affinity_data['cpufreq_governor']]):
with net_dev_groups_cpu_affinity(cpu_affinity_data['net_dev']):
with ProcessMgr(cpu_affinity_data['other']):
......@@ -809,6 +821,8 @@ def main(argv):
os.execlp(argv[0], *argv)
child_args = [cpu_affinity_data['lima']] + argv[2:]
global child
child = multiprocessing.Process(target=child_func,
args=child_args)
child.start()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment