Added a text banner that is displayed in the terminal/logfile on application startup, fixed a wrongly indented code block
This commit is contained in:
parent
6b396dbb50
commit
2c51e62a7d
1 changed files with 33 additions and 20 deletions
|
@ -14,6 +14,17 @@ from time import sleep
|
|||
from yaml import safe_load
|
||||
|
||||
|
||||
banner = """ ___ _ _
|
||||
| \ _ _ (_) _ _ | |__ ___ ___
|
||||
| |) || '_|| || ' \ | / /(_-< |___|
|
||||
|___/ |_| |_||_||_||_\_\/__/
|
||||
__ __ Version {version}
|
||||
| \/ | __ _ _ _ __ _ __ _ ___ _ _
|
||||
| |\/| |/ _` || ' \ / _` |/ _` |/ -_)| '_|
|
||||
|_| |_|\__,_||_||_|\__,_|\__, |\___||_|
|
||||
|___/
|
||||
"""
|
||||
|
||||
base_directory = Path(__file__).parent.parent
|
||||
data_directory = base_directory / "data"
|
||||
logfile_directory = data_directory / "logs"
|
||||
|
@ -79,27 +90,29 @@ def cleanup_procs(processes):
|
|||
|
||||
|
||||
def start_and_monitor(monitored_subprocesses: list):
|
||||
# display banner
|
||||
print(banner.format(version=os.environ["APP_VERSION"]))
|
||||
# start processes
|
||||
for p in monitored_subprocesses:
|
||||
p.try_start()
|
||||
register_exithandler(cleanup_procs, monitored_subprocesses)
|
||||
# monitor processes
|
||||
try:
|
||||
while True:
|
||||
sleep(1)
|
||||
for p in monitored_subprocesses:
|
||||
returncode = p.s.poll()
|
||||
if returncode is None:
|
||||
continue
|
||||
else:
|
||||
print(f"{p.name} stopped with exit code {returncode}.")
|
||||
if p.try_start() is False:
|
||||
# stop everything if the process
|
||||
# has exceeded max. tries
|
||||
exit()
|
||||
except KeyboardInterrupt:
|
||||
print("Received KeyboardInterrupt, exiting...")
|
||||
exit()
|
||||
for p in monitored_subprocesses:
|
||||
p.try_start()
|
||||
register_exithandler(cleanup_procs, monitored_subprocesses)
|
||||
# monitor processes
|
||||
try:
|
||||
while True:
|
||||
sleep(1)
|
||||
for p in monitored_subprocesses:
|
||||
returncode = p.s.poll()
|
||||
if returncode is None:
|
||||
continue
|
||||
else:
|
||||
print(f"{p.name} stopped with exit code {returncode}.")
|
||||
if p.try_start() is False:
|
||||
# stop everything if the process
|
||||
# has exceeded max. tries
|
||||
exit()
|
||||
except KeyboardInterrupt:
|
||||
print("Received KeyboardInterrupt, exiting...")
|
||||
exit()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue