''' except TypeError,e: print '%s send type error'%self.from_ip,e except KeyError,e: print '%s send keyerror'%self.from_ip def handler(signum,frame): global r r.flushall() #r.shutdown() sys.exit(0) if __name__=='__main__': signal.signal(signal.SIGINT,handler) signal.signal(signal.SIGTERM,handler) r=red.getredis() try: r.ping() except Exception,e: print e else: ps=r.pubsub() hosts=hs.hosts channels=hs.channels counter={} for h in hosts.values(): send_data={} channel=random.choice(hs.channels) send_data['channel']=channel temp_servers={} send_data['interval']={}
t.start() except MyException.MyException,e: print '\033[31m Error:%s \033[0m'%e.data class send_data_thread(threading.Thread): def __init__(self,data,channel,redis): threading.Thread.__init__(self) self.data=data self.channel=channel self.redis=redis def run(self): print {'data':self.data} self.redis.publish(self.channel,json.dumps({'data':self.data})) def exit_handler(signum,frame): global red global ip for item in red.client_list(): if item['addr'].startswith(ip): red.client_kill(item['addr']) sys.exit(0) if __name__=='__main__': signal.signal(signal.SIGINT,exit_handler) signal.signal(signal.SIGTERM,exit_handler) red=getredis.getredis() config=ConfigParser() config.read('config/config.py') interface=config.get('extra','interface') ip=getip.get_ip_address(interface) cli=client(red,ip) cli.start()