[Tutor] UPDATE: Is there a 'hook' to capture all exits from a python program?
Doug Basberg
dbasberg at comcast.net
Fri Mar 20 03:57:14 CET 2015
I do real-time controls programming and I control a relay in a python
program that must be turned off before the program ends. First, the program
should never exit unless I do it explicitly. Is there a 'hook' to process
before any exit (even if not expected). I must turn off that relay or harm
may occur. Thanks, Doug
Well, the harm is running down a solar battery bank and shortening the life
of the batteries. The relay that runs the inverter fed by the batteries
needs to turn off at a particular battery voltage level and within several
minutes. So, not time critical and not devastating consequences.
Given these circumstances, is there a point I can run some code on any exit?
I have decided to use a missing pulse circuit with a 2n3906 and 555 timer,
so that missing a pulse train will shut off the inverter. Then if Python
stops sending the 'watchdog' pulses, the inverter shuts down.
Still, I would like to know if a 'hook' exists on exit from Python. I am
running Linux on a Raspberry Pi with Python 2.7.4 I also run an Apache
server on the Pi for monitor and control of power, HVAC, and security.
Thanks, Doug
More information about the Tutor
mailing list