diff --git a/pymanager/manager.py b/pymanager/manager.py index 1960f53..093fbba 100755 --- a/pymanager/manager.py +++ b/pymanager/manager.py @@ -142,6 +142,7 @@ import json import fcntl import os import base64 +from socketserver import ThreadingMixIn try: import bcrypt @@ -455,7 +456,7 @@ class ManageHttpRequest(http.server.SimpleHTTPRequestHandler): self.end_headers() -class khaganatHTTPServer(http.server.HTTPServer): +class khaganatHTTPServer(ThreadingMixIn, http.server.HTTPServer): """ Class khaganatHTTPServer Redefine HTTPServer (adding queue input & queue output, use by ManageHttpRequest) @@ -669,38 +670,50 @@ class ManageCommand(): if not self.process: return "stopped" else: - code = self.process.poll() - loop = self.maxWaitEnd - while (code is None) and (loop > 0): - logging.debug("stop process %s", self.name) - self.process.send_signal(15) - time.sleep(1) + try: code = self.process.poll() - loop -= 1 + loop = self.maxWaitEnd + while (code is None) and (loop > 0): + logging.debug("stop process %s", self.name) + self.process.send_signal(15) + time.sleep(1) + code = self.process.poll() + loop -= 1 + except ProcessLookupError as e: + logging.warning("Stop process (%s)" % str(e)) - loop = self.maxWaitEnd - while (code is None) and (loop > 0): - logging.debug("terminate process %s", self.name) - self.process.terminate() - time.sleep(1) - code = self.process.poll() - loop -= 1 + try: + loop = self.maxWaitEnd + while (code is None) and (loop > 0): + logging.debug("terminate process %s", self.name) + self.process.terminate() + time.sleep(1) + code = self.process.poll() + loop -= 1 + except ProcessLookupError as e: + logging.warning("Stop process (%s)" % str(e)) - loop = self.maxWaitEnd - while (code is None) and (loop > 0): - logging.debug("kill process %s", self.name) - self.process.send_signal(9) - time.sleep(1) - code = self.process.poll() - loop -= 1 + try: + loop = self.maxWaitEnd + while (code is None) and (loop > 0): + logging.debug("kill process %s", self.name) + self.process.send_signal(9) + time.sleep(1) + code = self.process.poll() + loop -= 1 + except ProcessLookupError as e: + logging.warning("Stop process (%s)" % str(e)) - code = self.process.wait() - self.process = None - if self.threadRead: - self.eventRunning.clear() - self.threadRead.join() - self.threadRead = None - logging.info("%s stopped (return code:%d)" % (self.name, code)) + try: + code = self.process.wait() + self.process = None + if self.threadRead: + self.eventRunning.clear() + self.threadRead.join() + self.threadRead = None + logging.info("%s stopped (return code:%d)" % (self.name, code)) + except ProcessLookupError as e: + logging.warning("Stop process (%s)" % str(e)) return "stopped" def getlog(self, firstline): diff --git a/tests/test_manager.py b/tests/test_manager.py index 5502b5a..f362a50 100644 --- a/tests/test_manager.py +++ b/tests/test_manager.py @@ -339,7 +339,7 @@ class TestManager(unittest.TestCase): self.assertEqual(res, 'stopped') self.assertTrue(True) except Exception as e: - self.fail('Error when run test', e) + self.fail('Error when run test (%s)' % str(e)) def test_execute_command_crashed(self): try: