ail-framework/bin/launch_queues.py

66 lines
1.9 KiB
Python
Raw Normal View History

2018-04-16 12:50:04 +00:00
#!/usr/bin/env python3.5
2014-09-02 13:21:36 +00:00
# -*-coding:UTF-8 -*
2018-04-16 12:50:04 +00:00
import configparser
2014-09-02 13:21:36 +00:00
import os
import subprocess
import time
def check_pid(pid):
if pid is None:
# Already seen as finished.
return None
else:
if pid.poll() is not None:
return False
return True
if __name__ == '__main__':
configfile = os.path.join(os.environ['AIL_BIN'], 'packages/modules.cfg')
if not os.path.exists(configfile):
raise Exception('Unable to find the configuration file. \
Did you set environment variables? \
Or activate the virtualenv.')
2018-04-16 12:50:04 +00:00
config = configparser.ConfigParser()
2014-09-02 13:21:36 +00:00
config.read(configfile)
modules = config.sections()
pids = {}
for module in modules:
2018-04-16 12:50:04 +00:00
pin = subprocess.Popen(["python3", './QueueIn.py', '-c', module])
pout = subprocess.Popen(["python3", './QueueOut.py', '-c', module])
2014-09-02 13:21:36 +00:00
pids[module] = (pin, pout)
is_running = True
try:
while is_running:
time.sleep(5)
is_running = False
2018-04-16 12:50:04 +00:00
for module, p in pids.items():
2014-09-02 13:21:36 +00:00
pin, pout = p
if pin is None:
# already dead
pass
elif not check_pid(pin):
print(module, 'input queue finished.')
pin = None
else:
is_running = True
if pout is None:
# already dead
pass
elif not check_pid(pout):
print(module, 'output queue finished.')
pout = None
else:
is_running = True
pids[module] = (pin, pout)
except KeyboardInterrupt:
2018-04-16 12:50:04 +00:00
for module, p in pids.items():
2014-09-02 13:21:36 +00:00
pin, pout = p
if pin is not None:
pin.kill()
if pout is not None:
pout.kill()