from yaml import safe_load from io import open from threading import Thread from subprocess import run from time import sleep running_modules_dict = {} def print_modules(): for module in running_modules_dict: print(running_modules_dict[module] + " | ", end='') print(flush=True) def module_thread(name, cmd, refresh, pre, post): while True: result = pre result += run(cmd, shell=True, capture_output=True, text=True).stdout.strip() result += post running_modules_dict[name] = result print_modules() sleep(refresh/1000) with open("./testing_config.yml", 'r', encoding='utf8') as file: config_file = safe_load(file) modules = config_file['bar']['modules'] for module in modules: cmd = modules[module]['command'] refresh = modules[module]['refresh'] running_modules_dict[module] = '' x = Thread(target=module_thread, args=(module, cmd, refresh, '', '')) x.start()