From ac188ae8e4907709fdda9cb7e0173920255c8ed0 Mon Sep 17 00:00:00 2001 From: lework Date: Tue, 24 Mar 2020 16:52:44 +0800 Subject: [PATCH] fix threads error exit --- python/supervisor_healthCheck.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/python/supervisor_healthCheck.py b/python/supervisor_healthCheck.py index bc07f2a..d3a913b 100644 --- a/python/supervisor_healthCheck.py +++ b/python/supervisor_healthCheck.py @@ -576,12 +576,12 @@ class HealthCheck(object): :param program: :param pid: :return: - """ + """ self.log(program, 'Action: kill') result = 'success' if int(pid) < 3: - return 'Failed to kill %s, pid: %s '% (program, exitcode) + return 'Failed to kill %s, pid: %s '% (program, pid) cmd = "kill -9 %s" % pid exitcode, stdout, stderr = shell(cmd) @@ -771,9 +771,15 @@ class HealthCheck(object): t = threading.Thread(target=self.check, args=(item,)) threads.append(t) for t in threads: - t.setDaemon(True) - t.start() - + try: + t.setDaemon(True) + t.start() + except Exception, e: + print('Exception in ' + t.getName() + ' (catch by main)') + print(t.exc_traceback) + t.setDaemon(True) + t.start() + while 1: time.sleep(0.1)