#!/usr/bin/env python3 import logging from argparse import ArgumentParser from queue import Queue from sys import exit from time import sleep from conf import load_and_validate_config from dmx_queue import DMXQueue from mqtt_queue import MQTTQueue logging.basicConfig( level=logging.INFO, format="%(asctime)s %(name)20s [%(levelname)-8s] %(message)s", ) LOG = logging.getLogger("main") def main(): parser = ArgumentParser() parser.add_argument( "--config", default="config.toml", ) args = parser.parse_args() config = load_and_validate_config(args.config) LOG.info("Welcome to Voc2DMX") queues = {} dmx_workers = {} LOG.info("Initializing worker queues ...") mqttq = MQTTQueue(config, queues) mqttq.start() for universe in config.universes: queues[universe] = Queue() dmx_workers[universe] = DMXQueue(config, universe, queues[universe]) dmx_workers[universe].start() LOG.info("initialization done, now running. Press Ctrl-C to stop") try: while True: sleep(1) finally: LOG.warning("Got interrupt, stopping queues ...") mqttq.stop() for universe in config.universes: dmx_workers[universe].stop() LOG.info("Bye!") if __name__ == "__main__": main()