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.

Author Melebius
Recipients Melebius, chrahunt, glyph, gwk, kakshay, pablogsal, r.david.murray, torsten
Date 2019-01-24.08:56:05
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1548320165.79.0.966411651958.issue27035@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2019-01-24 08:56:07Melebiussetrecipients: + Melebius, glyph, r.david.murray, torsten, gwk, pablogsal, chrahunt, kakshay
2019-01-24 08:56:05Melebiussetmessageid: <1548320165.79.0.966411651958.issue27035@roundup.psfhosted.org>
2019-01-24 08:56:05Melebiuslinkissue27035 messages
2019-01-24 08:56:05Melebiuscreate