From 59ce880d1f81869ba156a8733e02ee818cf41c42 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Mon, 25 May 2020 15:52:38 +0530 Subject: [PATCH 1/3] fix: split command before feeding to Popen object --- gui.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gui.py b/gui.py index 4e470d2..373c0a4 100755 --- a/gui.py +++ b/gui.py @@ -1,6 +1,7 @@ import datetime import json import os +import shlex import sys import subprocess @@ -206,7 +207,8 @@ def integrate_biometric(self): if not hasattr(self, 'p'): print("Starting Service...") - self.p = subprocess.Popen('python -c "from erpnext_sync import infinite_loop; infinite_loop()"', stdout=subprocess.PIPE) + command = shlex.split('python -c "from erpnext_sync import infinite_loop; infinite_loop()"') + self.p = subprocess.Popen(command, stdout=subprocess.PIPE) print("Process running at {}".format(self.p.pid)) button.setText("Stop Service") create_message_box("Service status", "Service has been started") From 2ce1d2f1cbd4cd49837ec7aadeac95743f5e5fe6 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Mon, 25 May 2020 17:09:11 +0530 Subject: [PATCH 2/3] chore: print exceptions raised in main --- erpnext_sync.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/erpnext_sync.py b/erpnext_sync.py index d7a0e6d..fd3c5a3 100644 --- a/erpnext_sync.py +++ b/erpnext_sync.py @@ -307,8 +307,11 @@ def _safe_get_error_str(res): def infinite_loop(sleep_time=15): print("Service Running...") while True: - main() - time.sleep(sleep_time) + try: + main() + time.sleep(sleep_time) + except BaseException as e: + print(e) if __name__ == "__main__": infinite_loop() From d675d53d4c7bcd2fab6d502c6cf4a1b5def0e0fe Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Mon, 25 May 2020 17:09:35 +0530 Subject: [PATCH 3/3] fix: kill background process instead of terminating it --- gui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui.py b/gui.py index 373c0a4..18f2dc1 100755 --- a/gui.py +++ b/gui.py @@ -214,7 +214,7 @@ def integrate_biometric(self): create_message_box("Service status", "Service has been started") else: print("Stopping Service...") - self.p.terminate() + self.p.kill() del self.p button.setText("Start Service") create_message_box("Service status", "Service has been stoped")