I have a Raspberry Pi that runs a Python script on startup using the rc.local file.
To kill these processes run on startup, I use sudo pkill python in a terminal.
The problem with this is that code that should run on termination, like socket closing and OpenCV Video writer.release() don't get called.
Is there a way to "catch" the pkill as an exception so that those lines of code can be run?
If not, how else can I communicate from the terminal to a running Python script to change it's functionality and then terminate it.