This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Ambiguity about the semantics of sys.exit() and os._exit() in multithreaded program
Type: enhancement Stage:
Components: Documentation Versions: Python 3.1, Python 3.2, Python 2.7
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, exarkun, georg.brandl, gps, pakal, terry.reedy
Priority: normal Keywords:

Created on 2009-05-07 18:53 by pakal, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (3)
msg87389 - (view) Author: Pascal Chambon (pakal) * Date: 2009-05-07 18:53

I once was rather confused, because nothing in the sys and os modules
mentionned the behaviours that the exit() and _exit() functions were
supposed to have when called inside a non-main thread.
I've eventually found in multithreading-related docs that sys.exit()
made only the calling thread exit (without affecting the other threads
and the application), and I've eventually guessed that on the other
side, os._exit() always terminated the application wthout caring about
other threads or open files etc.
But I don't know if this will always be the case, or if using other
threading libraries than the standard one might change this semantics.

And concerning return code, I've found nothing indicating what happened
when different threads returned different codes. My experiments show
that only the main thread's return code is taken into account, but maybe
it's platform dependent (I'm on windows vista) ? 

So well, maybe we should add in the doc of sys and os some comments
about multithreading and returning codes, even if it is to say that
those are implementation details or platform dependant B-)

msg109672 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2010-07-09 03:24
I know nothing about this. You might check
to see if there has been any change or open a discussion on python-list to get suggestions for specific doc updates.
msg118931 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2010-10-17 10:52
Added a note about threads to sys.exit(), and changed os._exit() wording to be clear about process exit, in r85629.
Date User Action Args
2022-04-11 14:56:48adminsetgithub: 50212
2010-10-17 10:52:09georg.brandlsetstatus: open -> closed
resolution: fixed
messages: + msg118931
2010-08-07 18:32:51terry.reedysetversions: - Python 2.6
2010-07-09 10:45:30pitrousetnosy: + exarkun, gps
2010-07-09 03:24:05terry.reedysetversions: + Python 3.2, - Python 2.5, Python 3.0
nosy: + terry.reedy, docs@python

messages: + msg109672

assignee: georg.brandl -> docs@python
2009-05-07 18:53:14pakalcreate