Title: Correction to atexit documentation
Type: Stage:
Components: Documentation Versions: Python 2.7
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Jason.Baker, Rhamphoryncus, docs@python, georg.brandl, pitrou, r.david.murray
Priority: normal Keywords:

Created on 2010-10-07 21:34 by Jason.Baker, last changed 2010-10-14 06:43 by georg.brandl. This issue is now closed.

Messages (6)
msg118141 - (view) Author: Jason Baker (Jason.Baker) Date: 2010-10-07 21:34
There's an issue with the documentation on the atexit module[1].  It states:

"Note: the functions registered via this module are not called when the program is killed by a signal, when a Python fatal internal error is detected, or when os._exit() is called."

This isn't necessarily true.  For instance, if I start the following script:

from atexit import register
from time import sleep

def end():
    print 'atexit'

while True:

...and then do a "kill -SIGINT <pid>", the atexit function gets called.  It would be helpful to have a more detailed description of the rules on how this works.

msg118155 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-10-08 01:27
It is possible this behavior changed after the docs were written.  I'm adding a couple of people to nosy who might have some insight into that possibility.  It could be either a change in finalization procedures or a change in signal handling semantics, I think.
msg118158 - (view) Author: Adam Olsen (Rhamphoryncus) Date: 2010-10-08 02:38
Signals can directly kill a process.  Try SIGTERM to see this.  SIGINT is caught and handled by Python, which just happens to default to a graceful exit (unless stuck in a lib that prevents that.)  Try pasting your script into an interactive interpreter session and you'll see that it doesn't exit at all.
msg118165 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2010-10-08 06:36
One could also argue that on SIGINT, the program is not "killed" but "interrupted" by the signal :)

What about "... killed by an unhandled signal ..."?
msg118202 - (view) Author: Jason Baker (Jason.Baker) Date: 2010-10-08 14:40
I like that phrasing.  I think it would be a good idea to mention that this includes SIGINT by default, just to be explicit.
msg118622 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2010-10-14 06:43
Fixed in r85452.
Date User Action Args
2010-10-14 06:43:30georg.brandlsetstatus: open -> closed
resolution: fixed
messages: + msg118622
2010-10-08 14:40:36Jason.Bakersetmessages: + msg118202
2010-10-08 06:36:29georg.brandlsetnosy: + georg.brandl
messages: + msg118165
2010-10-08 02:38:26Rhamphoryncussetmessages: + msg118158
2010-10-08 01:27:12r.david.murraysetnosy: + r.david.murray, Rhamphoryncus, pitrou
messages: + msg118155
2010-10-07 21:34:53Jason.Bakercreate