监控进程更新代码




需求:如果agent_parent只是负责产生agent,那么用同步方法检查是否有异常即可:
  try:
subprocess.check_call(command, stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr)
except Exception as ex:
    ...

但是由于现在parent不仅仅需要负责产生agent还需要监控agent的进程个数是否异常,普通的同步以及异步:
def exec_shell_cmd_async(self,cmd_str):
subprocess.Popen(cmd_str, shell=True)

def exec_shell_cmd_sync(self,cmd_str):
child = subprocess.Popen(cmd_str, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell = True)
(out, err) = child.communicate()

由于parent产生以后 不能用同步方式挂起(直到agent退出),因为parent挂起只能监控parent的儿子,孙子挂了,他完全不知道,因此必须用异步方式,然后通过ps判断agent进程个数是否有问题
posted @ 2017-06-24 16:33  notlate  阅读(175)  评论(0)    收藏  举报