New submission from Thomas Kluyver <tho...@kluyver.me.uk>:

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.

----------
messages: 340607
nosy: takluyver
priority: normal
severity: normal
status: open
title: SystemExit & sys.exit : Allow both exit status and message
type: enhancement

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

Reply via email to