From 62b136724e2fb319ef225a6a6f4469c09ca58c48 Mon Sep 17 00:00:00 2001 From: Romain Bazile Date: Fri, 3 Dec 2021 02:04:43 +0100 Subject: [PATCH] Add kill by PID for the python script --- flows/main.json | 4 +++- scripts/main.py | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/flows/main.json b/flows/main.json index fe408d1..a62b119 100644 --- a/flows/main.json +++ b/flows/main.json @@ -7237,6 +7237,7 @@ "append": "", "useSpawn": "true", "timer": "", + "winHide": false, "oldrc": false, "name": "", "x": 1090, @@ -7305,11 +7306,12 @@ "id": "ed7503f3.d95a48", "type": "exec", "z": "9daf9e2b.019fc", - "command": "sudo killall -15 python3", + "command": "sudo kill -15 `cat /tmp/pscope_pid`", "addpay": false, "append": "", "useSpawn": "false", "timer": "", + "winHide": false, "oldrc": false, "name": "Python soft kill", "x": 740, diff --git a/scripts/main.py b/scripts/main.py index fd33c2e..65cb098 100644 --- a/scripts/main.py +++ b/scripts/main.py @@ -78,6 +78,10 @@ if __name__ == "__main__": signal.signal(signal.SIGINT, handler_stop_signals) signal.signal(signal.SIGTERM, handler_stop_signals) + # Create script PID file, so it's easy to kill the main process without ravaging all python script in the OS + with open('/tmp/pscope_pid', 'w') as f: + f.write(str(os.getpid())) + # check if gpu_mem configuration is at least 256Meg, otherwise the camera will not run properly with open("/boot/config.txt", "r") as config_file: for i, line in enumerate(config_file): @@ -190,4 +194,8 @@ if __name__ == "__main__": # module_thread.close() display.stop() + + # Cleanup pid file + os.remove('/tmp/pscope_pid') + logger.info("Bye")