[Tutor] UPDATE: Is there a 'hook' to capture all exits from a python program?
Cameron Simpson
cs at zip.com.au
Sun Mar 22 03:29:24 CET 2015
On 21Mar2015 09:19, Peter Otten <__peter__ at web.de> wrote:
>I ran a few experiments:
[...]
>Bonus:
>$ python3 bnb.py SIGTSTP
>Hello from 32614
>........^Zreceiving signal 20 (20, <frame object at 0x7f2f8a897648>)
>........^Cfinally
>except (<class 'KeyboardInterrupt'>, KeyboardInterrupt(), <traceback object
>at 0x7f2f895a2bc8>)
>exit
>
>So Ctrl-Z can be intercepted. The program could put the relay into a safe
>state before it suspends.
Yes, Ctrl-Z (SIGTSTP) can be caught ("stop from terminal", ^Z).
Note, however, that SIGSTOP cannot be caught ("stop"); it is not SIGTSTP.
Basicly you can kill (SIGKILL - abort process and never schedule it again),
stop (SIGSTOP - cease scheduling this process) and continue (SIGCONT - resume
scheduling this process) a process from outside a process and the process
cannot intercept these. Which is just great!
However, it means there are some things you cannot manage from within the
process. This is where watchdogs of various kinds come into play: an external
process of some kind which monitors the primary process (or something it
manages), and take action if the primary process goes away or some activity
does not occur for a period.
Cheers,
Cameron Simpson <cs at zip.com.au>
Cordless hoses have been around for quite some time. They're called buckets.
- Dan Prener <prener at watson.ibm.com>
More information about the Tutor
mailing list