Sys.exit in secondary threads

Ned Deily nad at
Fri Oct 8 23:14:37 CEST 2010

In article 
<d841072f-5bad-4b2c-ba14-977b77645c2e at>,
 Pakal <chambon.pascal at> wrote:
> I've noticed that there is nothing in python's documentation regarding
> the use of sys.exit(code) in a non-main thread.
> As far as I've seen, the behaviour in this case is to simply exit the
> thread, without caring about the return code. in the main thread
> however, the return code becomes the official return code of the whole
> process.
> Is that all we have to say about sys.exit() in a multithreaded
> program ? Or are there corner cases I've missed ? We'd better document
> this anyway.

There is this item among the Caveats for the _thread module in Py3 
(thread in Py2):

"Calling sys.exit() or raising the SystemExit exception is equivalent to 
calling _thread.exit()."

It seems like it should be mentioned elsewhere, too, like in sys.exit() 
itself.  Doc patches would be welcomed, I'm sure.

 Ned Deily,
 nad at

More information about the Python-list mailing list