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 takluyver
Recipients takluyver
Date 2019-04-21.13:04:32
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1555851872.77.0.954312917312.issue36691@roundup.psfhosted.org>
In-reply-to
Content
The SystemExit exception, and consequently the sys.exit() function,  take a single parameter which is either an integer exit status for the process, or a message to print to stderr before exiting - in which case the exit status is implicitly 1.

In certain situations, it would be useful to pass both an exit status and a message. E.g. when argparse handles '--help', it wants to display a message and exit successfully (status 0). You may also use specific exit codes to indicate different kinds of failure.

Printing the message separately before raising SystemExit is not an entirely satisfactory subsitute, because the message attached to the exception is only printed if it is unhandled. E.g. for testing code that may raise SystemExit, it's useful to have the message as part of the exception.

I imagine that the trickiest bit of changing this would be ensuring as much backwards compatibility as possible. In particular, SystemExit exceptions have a 'code' attribute which can be either the exit status or the message.
History
Date User Action Args
2019-04-21 13:04:32takluyversetrecipients: + takluyver
2019-04-21 13:04:32takluyversetmessageid: <1555851872.77.0.954312917312.issue36691@roundup.psfhosted.org>
2019-04-21 13:04:32takluyverlinkissue36691 messages
2019-04-21 13:04:32takluyvercreate