啥也不说了,先贴代码:defmonitor(client):run_heartbeat=client.run.heartbeatetc_rpc=client.etc.rpcdocument=etc_rpc.find_one({'server':'taskmanager'})rpc=document['host']+':'+document['port']ifprocess_ok('taskmanager'):run_heartbeat.update({'process':'taskmanager','rpc':rpc},{'$set':{'selftesttime':datetime.datetime.now().strftime('%Y-%m-%d%H:%M:%S'),'selftest':'ok'}})logging.info("update:selftestis'ok'")print"update:run_heartbeat.taskmanager.selftestis'ok'"else:run_heartbeat.update({'process':'taskmanager','rpc':rpc},{'$set':{'selftesttime':datetime.datetime.now().strftime('%Y-%m-%d%H:%M:%S'),'selftest':'processerror'}})logging.info("update:selftestis'processerror'")print"update:run_heartbeat.taskmanager.selftestis'processerror'"if__name__=="__main__":print"TaskMonitorbeginning......"sched=Scheduler()sched.daemonic=Falsesched.add_interval_job(monitor,seconds=int(tasktime),args=[client])sched.start()功能:每隔tasktime秒就运行一次monitor函数期望结果:在运行过程中通过CTRL+C停止求大神解决办法!
2 回答
梦里花落0921
TA贡献1772条经验 获得超6个赞
安装一个signalhandler即可importsignal,osdefhandler(signum,frame):print"gotsignal",signumifsignum==signal.SIGINT:print"gotCtrl+C,wewillquit"os._exit(1)signal.signal(signal.SIGINT,handler)if__name__=='__main__':importtimewhileTrue:time.sleep(1)
添加回答
举报
0/150
提交
取消