def watchdog(redis_threads): ''' watch threads and daemon it :param redis_threads: :return: None ''' while True: threads = set() for item in threading.enumerate(): threads.add(item.name) log.debug("###" * 20) log.debug(redis_threads) log.debug(threads) if threads - {'watchdog', 'MainThread'} != redis_threads: dead_threads = redis_threads - (threads - {'watchdog', 'MainThread'}) conf_file = os.path.abspath('conf/chitu.toml') conf = get_conf(conf_file) addresses = conf['redis']['address'] for dead_thread in dead_threads: address = [i for i in addresses if i['db'] == dead_thread[-1]][0] thread_name = 'redis_' + str(address['db']) messenger = Messenger(conf, address) t_worker = threading.Thread(target=messenger.run, name=thread_name, args=[]) t_worker.setDaemon(True) t_worker.start() time.sleep(10)
def main(): """ Multi-threaded crawling redis data sent to influxdb """ appname = "chitu" parser = get_option_parser(appname) options, args = parser.parse_args() conf_file = os.path.abspath(options.config) conf = get_conf(conf_file) setup_logger(conf['logging']) log.debug("start...") thread_set = set() thread_name_set = set() # messenger who send msg to influxdb for redis_address in conf['redis']['address']: messenger = Messenger(conf, redis_address) thread_name = 'redis_' + str(redis_address['db']) if thread_name in thread_name_set: raise Exception('threat name exists') else: thread_name_set.add(thread_name) # messenger.run() t_worker = threading.Thread(target=messenger.run, name=thread_name, args=[]) t_worker.setDaemon(True) t_worker.start() thread_set.add(thread_name) t_watchdog = threading.Thread(target=watchdog, name='watchdog', args=[thread_set]) t_watchdog.setDaemon(True) t_watchdog.start() if conf['Deamon']['deamon']: deamon(conf['Deamon']['process_name'], conf['Deamon']['cmd'])
def main(): """ main """ appname = "winwin" ### prepare configuration and logger parser = get_option_parser(appname) options, args = parser.parse_args() conf_file = os.path.abspath(options.config) conf = get_conf(conf_file) setup_logger(conf['logging']) log.debug("start...") ### init threads plugin_threads = setup(conf) ### main loop while True: threads = set() for item in threading.enumerate(): #print dir(item) #print item if item.name == 'Checker': #item.exits() pass threads.add( item.name ) #log.debug(plugin_threads) #log.debug(threads) ### check if the worker thread is there. if not threads.issuperset(plugin_threads): ### stop thread and start again #setup(conf) pass time.sleep(conf['app']['interval'])
def main(): """ main """ appname = "winwin" parser = get_option_parser(appname) options, args = parser.parse_args() conf_file = os.path.abspath(options.config) conf = get_conf(conf_file) setup_logger(conf['logging']) log.debug("start...") worker = Worker(conf) worker.run()
def main(): """ main """ appname = "chitu" parser = get_option_parser(appname) options, args = parser.parse_args() conf_file = os.path.abspath(options.config) conf = get_conf(conf_file) setup_logger(conf['logging']) log.debug("start...") ### messenger who send msg to influxdb messenger = Messenger(conf) messenger.run()
def __init__(self, path_plugin, plugin): self.g = Global() ### get configuration #self.conf = self.g.conf #self.conf = self.g.conf[channel] self.channel = plugin['channel'] dir_plugin = os.path.dirname(path_plugin) conf_file_name = "{}.toml".format(self.channel) conf_file = os.sep.join([dir_plugin, conf_file_name]) self.conf = get_conf(conf_file)['channel'] self.in_q = self.g.get_queue(plugin['in_q']) self.out_q = self.g.get_queue(plugin['out_q'])
def main(appname): """ main """ ### prepare configuration and logger parser = get_option_parser(appname) options, args = parser.parse_args() conf_file = os.path.abspath(options.config) conf = get_conf(conf_file) setup_logger(conf['logging']) log.debug("start...") ### init threads setup(conf) ### main loop while True: time.sleep(1)