RPi is configured headless and operated via ssh. Running a Python script by using a service.
The script exits via Ctl+S which is captured by an Exception. On the Exception the script writes data to a file, closes file and Exits. The script also has an Except line that is supposed to capture any other anomaly and write, closes file and exit.
In order to overcome the ssh connection giving a “broken pipe” message due to inactivity, I am running the script as a service which starts on boot. Problem is when I disable the service the script stops running (as expected) but since neither Ctl+S or another exception is generated when the service is disabled no data is being written in the Exception part of the script.
Can a service trigger some exception that can be captured by the script and be used to gracefully end the script?