def main(): parser = argparse.ArgumentParser() parser.add_argument("-v", "--verbose", action="store_true", default=False) args = parser.parse_args() log_format = "%(asctime)s %(levelname)-8s %(processName)-10s %(name)-10s %(message)s" if args.verbose: logging.basicConfig(format=log_format, level=logging.DEBUG) else: logging.basicConfig(format=log_format, level=logging.INFO) log = logging.getLogger() loop = asyncio.get_event_loop() server = WatchDog() try: log.info("Start all service") server.start() loop.run_forever() except KeyboardInterrupt: log.info("Receive close signal") except: log.info(sys.exc_info()) loop.run_until_complete(asyncio.wait([shutdown(server)])) loop.close() if loop.is_closed(): loop.stop()
if __name__ == '__main__': # gt = guiThread() # gt.start() #Declare the run_time run_time_in_seconds = 4 threads = [] queue = queue.Queue() queue.maxsize = 20 #Create 2 Producer and 3 Consumer p1 = Producer(queue) c1 = Consumer(queue) p2 = Producer(queue) c2 = Consumer(queue) c3 = Consumer(queue) #Add them to the list threads.append(p1) threads.append(c1) threads.append(p2) threads.append(c2) threads.append(c3) #Initialize watchdog object w = WatchDog(run_time_in_seconds, *threads) w.start() #Start and wait for threads to finish for thread in threads: thread.start() for thread in threads: thread.join() w.join() # gt.join()
app_options = get_app_options() # 3. initialize global logger loggerfactory = LoggerFactory(__name__) if app_options['app_debug']: loggerfactory.add_handler(handler='CONSOLE', format=DEFAULT_LOG_FORMAT, log_dir=LOG_PATH, log_name=LOG_FILE_NAME, level='INFO') loggerfactory.add_handler(handler='TIME_FILE', format=DEFAULT_LOG_FORMAT, log_dir=LOG_PATH, log_name=LOG_FILE_NAME, level='INFO') logger = loggerfactory.get_logger() logger.info("Launch options: %s" % str(app_options)) # 4. initialize functional components and api resources event_reporter = None if app_options['app_event']: logger.info("Event reporter: select real event collector client") event_reporter = EventReporter(logger=logger) else: logger.info("Event reporter: select fake reporter") event_reporter = FakeReporter(logger=logger) # wait for completion of event reporter initialization time.sleep(5) watchdog = WatchDog(contacts=app_options['contacts'], reporter=event_reporter, logger=logger, alive=app_options['app_alive']) watchdog.start() api.add_resource(SensorReportAPI, '/report', '/report//', resource_class_kwargs={ 'event_reporter': event_reporter, 'watchdog': watchdog, 'logger': logger}) if __name__ == "__main__": # launch the app app.run(debug=True, port=5000)
series[data_node['host']]['metadata'].append(data_node) summary = status[0] if status else {} return data({ "nodes": nodes, "time_lines": time_lines, "series": [value for key, value in series.items()], "summary": summary }) @app.route('/login', methods=['POST']) def login(): form_data = request.get_json() # TODO: should validation from the database later if form_data['username'] == 'admin': return success('登录成功') return error('登录失败') if __name__ == '__main__': # 开始运行整体程序 logger.info('start the server ...') watch_dog = WatchDog( options=options, data_nodes=data_nodes, ) watch_dog.start() logger.info('server has been started ...') app.run(port=5000, host='0.0.0.0')