Sys.exit in secondary threads

P

Pakal

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.

Regards,
Pascal
 
N

Ned Deily

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,058
Latest member
QQXCharlot

Latest Threads

Top