def main(): args = get_args() setup_logging(args) options = dict(args.__dict__) options.update({ "format": args.format.strip(), "dimensions": (args.width, args.height), "outputSize": (args.dimension, args.dimension), "draw_debug_rects" : False, "draw_final_rects" : False, "color_model" : args.color_model.upper() }) if not args.cpus : options["cpus"] = os.cpu_count() logging.info("Image dimensions: {dimensions} format: {format}".format_map(options)) if args.profile : pr = cProfile.Profile() pr.enable() for i in range(args.initial, args.initial + args.count) : count, elapsed = pr.runcall(make_page, *(str(i), options)) print(count, elapsed) if elapsed > 2 : ps = pstats.Stats(pr) ps.sort_stats('cumtime') ps.print_stats(0.1) pr.clear() elif args.daemon : logging.info("Starting webserver, queue size {}".format(args.count)) server = Webserver(options) server.start_server() else : logging.info("Writing images to: {output_directory}".format_map(options)) logging.info("Generating {} images starting at {}".format(args.count, args.initial)) if options["cpus"] == 1 : for i in range(args.initial, args.initial + args.count) : num, elapsed = make_page(str(i), options) print("{} - {} images in {:.2f} seconds".format(i, num, elapsed)) else: mp.freeze_support() generate_pages(options)
config = {} with open(config_path, 'r') as ymlfile: config = yaml.load(ymlfile, Loader=yaml.SafeLoader) logger.info("Loaded %d configuration items from %s" % (len(config), config_path)) # Create the AT command poller at_poller = Poller( config['at']['dev'], config['at']['poll_delay'], config['at']['statsd'] if 'statsd' in config['at'] else None) at_poller.start() # Create the internet connection checker ip_checker = InternetChecker() # Create the supervisor instance cm_supervisor = Supervisor(config['cm']['path'], config['cm']['respawn_delay'], config['cm']['apn'], config['cm']['log_lines'], at_poller, ip_checker) cm_supervisor.start() # Create the webserver server = Webserver(config['web']['port'], at_poller, cm_supervisor, ip_checker) # Start the server server.start_server() # Keep the main thread alive in case the web server was configured not to start while cm_supervisor.is_supervising: time.sleep(1)