summaryrefslogtreecommitdiffstats
path: root/src/ogRest.py
diff options
context:
space:
mode:
authorAlvaro Neira Ayuso <aneira@soleta.eu>2020-02-23 18:06:01 +0100
committerAlvaro Neira Ayuso <aneira@soleta.eu>2020-02-24 09:35:24 +0100
commit6f7ba325b818ae6fcfd373566afdb72eb4f55d55 (patch)
treec73b7fe3a332b2dcfd1a39767a3949e755fcac63 /src/ogRest.py
parent583057bd6953548aa429a71f5f87c30a52c49840 (diff)
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.
Diffstat (limited to 'src/ogRest.py')
-rw-r--r--src/ogRest.py29
1 files changed, 17 insertions, 12 deletions
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)