From 6f7ba325b818ae6fcfd373566afdb72eb4f55d55 Mon Sep 17 00:00:00 2001 From: Alvaro Neira Ayuso Date: Sun, 23 Feb 2020 18:06:01 +0100 Subject: Modify way to close PID process With our client disconnection, we hid that the ogClient process will be closed too. This new way only close the subprocess keeping the ogClient still working. --- src/ogRest.py | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/ogRest.py b/src/ogRest.py index 25a111f..f6b8ca4 100644 --- a/src/ogRest.py +++ b/src/ogRest.py @@ -291,6 +291,20 @@ class ogRest(): return 0 + def kill_process(self): + try: + os.kill(self.proc.pid, signal.SIGTERM) + except: + pass + + time.sleep(2) + try: + os.kill(self.proc.pid, signal.SIGKILL) + except: + pass + + self.state = ThreadState.IDLE + def process_reboot(self, client): response = restResponse(ogResponses.IN_PROGRESS) client.send(response.get()) @@ -298,10 +312,7 @@ class ogRest(): client.disconnect() if self.state == ThreadState.BUSY: - os.killpg(os.getpgid(self.proc.pid), signal.SIGTERM) - time.sleep(2) - os.killpg(os.getpgid(self.proc.pid), signal.SIGKILL) - self.state = ThreadState.IDLE + self.kill_process() threading.Thread(target=ogThread.reboot).start() @@ -312,10 +323,7 @@ class ogRest(): client.disconnect() if self.state == ThreadState.BUSY: - os.killpg(os.getpgid(self.proc.pid), signal.SIGTERM) - time.sleep(2) - os.killpg(os.getpgid(self.proc.pid), signal.SIGKILL) - self.state = ThreadState.IDLE + self.kill_process() threading.Thread(target=ogThread.poweroff).start() @@ -358,10 +366,7 @@ class ogRest(): def process_stop(self, client): client.disconnect() if self.state == ThreadState.BUSY: - os.killpg(os.getpgid(self.proc.pid), signal.SIGTERM) - time.sleep(2) - os.killpg(os.getpgid(self.proc.pid), signal.SIGKILL) - self.state = ThreadState.IDLE + self.kill_process() self.terminated = True sys.exit(0) -- cgit v1.2.3-18-g5258