Python detect linux shutdown and run a command before shutting down
<p>Is it possible to detect and interrupt linux (Ubuntu 16.04) shutdown signal (e.g. power button clicked or runs out of battery). I have a python application that is always recording a video and I want to detect such signal so I close the recording properly before OS shutdown.</p>

<p>Look into <a href="http://askubuntu.com/questions/1175/execute-script-before-shutting-down">this</a>
Basically, put a script in /etc/rc0.d/ with the right name and execute a call to you python script. </p>

python linux python-2.7 ubuntu