This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: atexit errors should result in nonzero exit code
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.4
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: amaury.forgeotdarc, aminusfu, benjamin.peterson, christian.heimes, doughellmann, gvanrossum, lakin.wecker, pitrou, titus, vstinner, ysj.ray
Priority: normal Keywords:

Created on 2007-10-10 19:56 by aminusfu, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
ghop-215-py2.6-ctb.diff titus, 2008-01-08 10:47 Working patch with doc+test against latest trunk. review
Messages (11)
msg56323 - (view) Author: Robert Brewer (aminusfu) Date: 2007-10-10 19:56
While debugging/fixing the logging module's atexit behavior (see
http://www.cherrypy.org/ticket/646 -- it chokes atexit if stdout is
closed), it became difficult to write an automated test that verified
the bug occurred, since it happened at program exit. Returning a nonzero
exit code when atexit errors occur would be preferable to just printing
the error. Of course, if SystemExit is already raised, we should
propagate that out, but other exceptions should print the traceback and
then return some other code IMO.
msg56324 - (view) Author: Lakin Wecker (lakin.wecker) Date: 2007-10-10 20:03
I am an agreeance with the original report.  I just finished writing an
automated test that did the following to work around this behavior:

 	46	        # Sometimes an exception happens during exit, try to make
sure we get   
 	47	        # a non_zero exit code. 
 	48	        old_exitfunc = sys.exitfunc 
 	49	        def exitfunc(): 
 	50	            try: 
 	51	                old_exitfunc() 
 	52	            except SystemExit: 
 	53	                raise 
 	54	            except: 
 	55	                raise SystemExit(1)
msg56325 - (view) Author: Lakin Wecker (lakin.wecker) Date: 2007-10-10 20:04
sorry for the noise and duplication.  The full code listing should have
been:

 	46	        # Sometimes an exception happens during exit, try to make
sure we get   
 	47	        # a non_zero exit code. 
 	48	        old_exitfunc = sys.exitfunc 
 	49	        def exitfunc(): 
 	50	            try: 
 	51	                old_exitfunc() 
 	52	            except SystemExit: 
 	53	                raise 
 	54	            except: 
 	55	                raise SystemExit(1) 
 	56	        sys.exitfunc = exitfunc
msg57677 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2007-11-20 00:51
The issue should be addressed in the C code.
msg59529 - (view) Author: Titus Brown (titus) Date: 2008-01-08 10:47
Please see GHOP patches by anders_v...@yahoo.se,

http://code.google.com/p/google-highly-open-participation-psf/issues/detail?id=215

I've attached the Python 2.6 patch here.
msg67043 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-05-18 21:18
I'm assigning this to Christian because he was doing the GHOP review.
msg116780 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2010-09-18 14:05
Can someone please review the attached patch with a view to committing, it contains doc and unit test changes.
msg117159 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2010-09-22 23:20
exit code = 128 + # of failed atexits

I don't agree with the feature. Do we need something so complex?
msg132590 - (view) Author: ysj.ray (ysj.ray) Date: 2011-03-30 13:57
I think there is no need to implement this in python2.x since it's a  behavior change which could introduce some compatibility issues to someone's code, besides in 2.x both sys.exitfunc and atexit module should be considered, that makes the code looks complex. The sys.exitfunc is removed in 3.x.

+1 on only implementing it in 3.3.
msg195587 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-08-18 23:16
I would disagree with this report. There are many errors which are effectively silenced by Python, except for being printed on stderr: for example, errors which occur in a __del__ method or a weakref callback (both of which semantically similar to an atexit handler); but also exceptions which terminate a non-main thread.

Python's error code is derived from the return status of the main thread of execution, not counting any kinds of asynchronous exceptions, which are simply displayed and then ignored.

If you want to write a test for errors at program exit, you should check for stderr's contents (by capturing it).
msg342549 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-05-15 03:11
Antoine disagrees with the feature request, so I close it.

You can modify your atexit callbacks to catch exceptions and decide how to handle them: write them into a file, into stderr, etc.
History
Date User Action Args
2022-04-11 14:56:27adminsetgithub: 45598
2019-05-15 03:11:04vstinnersetstatus: open -> closed

nosy: + vstinner
messages: + msg342549

resolution: rejected
stage: patch review -> resolved
2014-02-03 17:03:07BreamoreBoysetnosy: - BreamoreBoy
2013-08-18 23:16:48pitrousetnosy: + pitrou
messages: + msg195587
2013-08-18 22:37:47doughellmannsetnosy: + doughellmann
2013-06-24 17:09:01christian.heimessetassignee: christian.heimes ->
versions: + Python 3.4, - Python 3.1, Python 2.7, Python 3.2, Python 3.3
2011-03-30 13:57:52ysj.raysetnosy: + ysj.ray

messages: + msg132590
versions: + Python 3.3
2010-09-22 23:20:59amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg117159
2010-09-18 14:05:06BreamoreBoysetversions: - Python 2.6
nosy: + BreamoreBoy

messages: + msg116780

stage: patch review
2010-06-09 22:19:50terry.reedysetversions: + Python 3.1, Python 2.7, Python 3.2, - Python 2.5, Python 2.4, Python 3.0
2008-05-18 21:18:24benjamin.petersonsetassignee: gvanrossum -> christian.heimes
messages: + msg67043
nosy: + benjamin.peterson
2008-01-08 10:47:08titussetfiles: + ghop-215-py2.6-ctb.diff
nosy: + titus
messages: + msg59529
2007-11-20 00:51:03christian.heimessetpriority: normal
assignee: gvanrossum
messages: + msg57677
nosy: + christian.heimes, gvanrossum
2007-10-10 20:04:47lakin.weckersetmessages: + msg56325
2007-10-10 20:03:54lakin.weckersetnosy: + lakin.wecker
messages: + msg56324
2007-10-10 19:56:26aminusfucreate