Miroslav Matějů <meleb...@gmail.com> added the comment:

I completely support @gwk’s opinion expressed in his comments. My original 
intention has been to set the exit code in an atexit callback. I tried a way 
and found that it was working in Python 2.7 but not in 3.x (without notice), so 
I filed this bug report. (See also the Stack Overflow link in my first post.)

I don’t find this just a documentation issue since it prevents the user from 
setting the exit code, although (as correctly stated by @gwk): “Ultimately, it 
is the responsibility of the application programmer to return an appropriate 
code for all execution paths” and “returning the correct code is the most 
critical behavior of a process”.

My use case is a testing library. The user calls assertions from my library and 
when their script finishes, my library is responsible for deciding whether the 
test has passed (and finishing the log). Before porting the library to Python 
(3.5 initially), I used to indicate successfulness by the exit code. With 
Python 3.x, I am forced to either:
1) print a result message and let the parent process parse it (implemented 
currently), or
2) force the user of my library to include something like
     sys.exit(testlib.result())
   as the last line of their scripts which I find annoying and error-prone.

I cannot decide whether calling sys.exit() in an atexit callback means breaking 
the contract as @r.david.murray states. However, the user shall be able to set 
the exit code of their application when it finishes and atexit should support 
some way to do that.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue27035>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to