Sys.exit in secondary threads

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


In article 
<d841072f-5bad-4b2c-ba14-977b77645c2e at a15g2000yqm.googlegroups.com>,
 Pakal <chambon.pascal at gmail.com> 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()."

http://docs.python.org/py3k/library/_thread.html
http://docs.python.org/library/thread.html

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 acm.org




More information about the Python-list mailing list