Add kill by PID for the python script

This commit is contained in:
Romain Bazile 2021-12-03 02:04:43 +01:00
parent 0e3a71b322
commit 62b136724e
2 changed files with 11 additions and 1 deletions

View file

@ -7237,6 +7237,7 @@
"append": "", "append": "",
"useSpawn": "true", "useSpawn": "true",
"timer": "", "timer": "",
"winHide": false,
"oldrc": false, "oldrc": false,
"name": "", "name": "",
"x": 1090, "x": 1090,
@ -7305,11 +7306,12 @@
"id": "ed7503f3.d95a48", "id": "ed7503f3.d95a48",
"type": "exec", "type": "exec",
"z": "9daf9e2b.019fc", "z": "9daf9e2b.019fc",
"command": "sudo killall -15 python3", "command": "sudo kill -15 `cat /tmp/pscope_pid`",
"addpay": false, "addpay": false,
"append": "", "append": "",
"useSpawn": "false", "useSpawn": "false",
"timer": "", "timer": "",
"winHide": false,
"oldrc": false, "oldrc": false,
"name": "Python soft kill", "name": "Python soft kill",
"x": 740, "x": 740,

View file

@ -78,6 +78,10 @@ if __name__ == "__main__":
signal.signal(signal.SIGINT, handler_stop_signals) signal.signal(signal.SIGINT, handler_stop_signals)
signal.signal(signal.SIGTERM, 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 # 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: with open("/boot/config.txt", "r") as config_file:
for i, line in enumerate(config_file): for i, line in enumerate(config_file):
@ -190,4 +194,8 @@ if __name__ == "__main__":
# module_thread.close() # module_thread.close()
display.stop() display.stop()
# Cleanup pid file
os.remove('/tmp/pscope_pid')
logger.info("Bye") logger.info("Bye")