[docs] [issue6634] sys.exit() called from threads other than the main one: undocumented behaviour

David Manowitz report at bugs.python.org
Mon Mar 26 19:40:33 CEST 2012


David Manowitz <david.manowitz at gmail.com> added the comment:

I have a couple of issues with that argument:

1.) Until fairly recently, the fact that sys.exit() when called from a
non-primary thread only causes the thread to die, was not clearly
documented (and still isn't in the python2.6 docs).  Admittedly,
thread.exit() does say that it raises the SystemExit exception, but as most
people are encouraged to use the *threading* module, rather than the
*thread* module directly, this is still fairly obscure.

2.) A ThreadExit exception could be derived from the SystemExit exception,
so existing code that works by catching a SystemExit exception would still
work.

--David

On Sat, Mar 24, 2012 at 6:47 AM, Antoine Pitrou <report at bugs.python.org>wrote:

>
> Antoine Pitrou <pitrou at free.fr> added the comment:
>
> > I don't see why this should be considered acceptable behavior.  Why
> > don't threads have their own ThreadExit exception, rather than
> > overloading the use, and therefore, the meaning, of the SystemExit
> > exception?  As indicated by their names, sys.exit and the SystemExit
> > exception should *only* be used to exit the entire system, not just a
> > thread!
>
> I agree the situation isn't optimal. However, fixing this would also break
> compatibility with any application that uses sys.exit() in a thread and
> expects it to exit the thread, not the whole process. So we're kind of
> stuck with it.
>
> ----------
> nosy: +pitrou
>
> _______________________________________
> Python tracker <report at bugs.python.org>
> <http://bugs.python.org/issue6634>
> _______________________________________
>

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue6634>
_______________________________________


More information about the docs mailing list