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.

classification
Title: sys.exit() exits program when non-daemonic threads are still running
Type: behavior Stage: needs patch
Components: Documentation Versions: Python 3.1, Python 3.2, Python 2.7, Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder: Thread shutdown exception in Thread.notify()
View: 1722344
Assigned To: georg.brandl Nosy List: eggy, georg.brandl, jmalicki, r.david.murray
Priority: normal Keywords:

Created on 2008-12-17 17:59 by eggy, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
foo.py eggy, 2008-12-17 17:59 test case
threading_exit_example.py r.david.murray, 2009-08-27 00:59
Messages (4)
msg77978 - (view) Author: Mark Florisson (eggy) * Date: 2008-12-17 17:59
sys.exit() exits the program when non-daemonic threads are still
running, in versions >= 2.5. 

Test included. A demonstration here: http://paste.pocoo.org/show/95766/
(On debian GNU/Linux)
msg91985 - (view) Author: Joseph Malicki (jmalicki) Date: 2009-08-26 22:28
It seems like this was introduced by the fix for Issue 1566280.

Note that the threading module docs clear state:

"A thread can be flagged as a “daemon thread”. The significance of this
flag is that the entire Python program exits when only daemon threads
are left. The initial value is inherited from the creating thread. The
flag can be set through the daemon property."

This behavior violates it.

The WaitForThreading() fix in Py_Main works only if sys.exit() is not
called, which disagrees with the documentation.
msg91991 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2009-08-27 00:59
Attached is a version of your program that calls sys.exit from a thread
other than the main one.  That sys.exit does not cause python to shut
down.  Exiting the main program by "falling off the end" does not result
in Python shutdown (pass an arbitrary argument to the example program to
see this). 

So what we have here, I believe, is a documentation problem, and I've
updated the issue to reflect that.  Please note in particular the last
two caveats in the 'thread' docs; I don't consider these adequate
documentation, but they do seem to be relevant to the issue at hand.

Does this make sense to you?

Note that issue 6634 should also be addressed in any update to the
relevant areas of the documentation.
msg91993 - (view) Author: Joseph Malicki (jmalicki) Date: 2009-08-27 02:17
Is it actually just documentation?  Before Python 2.5, things worked
according to the documentation, and nothing in the revisions that
changed the behavior suggested this change in behavior was intentional.

Moving the WaitForThreadShutdown() from Modules/main.c to Py_Finalize()
would also fix this problem - I wonder why that wasn't the original
change, as it more closely mirrors how Python 2.4 worked, and the
documentation suggests?
History
Date User Action Args
2022-04-11 14:56:42adminsetgithub: 48934
2010-09-28 22:14:32twouterssetstatus: open -> closed
resolution: fixed
superseder: Thread shutdown exception in Thread.notify()
2009-08-27 02:17:32jmalickisetmessages: + msg91993
2009-08-27 00:59:13r.david.murraysetfiles: + threading_exit_example.py
priority: normal

components: + Documentation, - None
assignee: georg.brandl
versions: + Python 3.1, Python 2.7, Python 3.2, - Python 2.5, Python 3.0
nosy: + georg.brandl, r.david.murray

messages: + msg91991
stage: needs patch
2009-08-26 22:28:53jmalickisetnosy: + jmalicki
messages: + msg91985
2008-12-17 17:59:07eggycreate