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.

Author etuardu
Recipients docs@python, etuardu, r.david.murray
Date 2011-10-01.13:43:58
SpamBayes Score 8.96735e-05
Marked as misclassified No
Message-id <1317476639.29.0.288812849627.issue13077@psf.upfronthosting.co.za>
In-reply-to
Content
Let me put it this way: the definition of daemon thread describes the behaviour of the Python program running it (its exit condition in particular) instead of going straight to the point describing the behaviour of the daemon thread itself first, and finally add other considerations.

Specifically, I think a situation like the following is not quite clear from the given definition:
- I have a main thread and a secondary thread, both printing to stdout.
- At some point, I press Ctrl+c raising an unhandled KeyboardInterrupt exception in the main thread, which kills it.

This is what I get using a daemon thread:

etuardu@subranu:~/Desktop$ python foo.py # other = daemon
other thread
main thread
other thread
main thread
^C
Traceback [...]
KeyboardInterrupt
etuardu@subranu:~/Desktop$ # process terminates

This is what I get using a non-daemon thread:

etuardu@subranu:~/Desktop$ python foo.py # other = non-daemon
other thread
main thread
other thread
main thread
^C
Traceback [...]
KeyboardInterrupt
other thread
other thread
other thread
... (process still running)

So, to explain the significance of the "daemon" flag, I'd say something like:

A daemon thread is shut down when the main thread and all others non-daemon threads end.
This means a Python program runs as long as non-daemon threads, such as the main thread, are running.
When only daemon threads are left, the Python program exits.

Of course this can be understood from the current definition («the entire Python program exits when only daemon threads are left»), still it looks a bit sybilline to me.
History
Date User Action Args
2011-10-01 13:43:59etuardusetrecipients: + etuardu, r.david.murray, docs@python
2011-10-01 13:43:59etuardusetmessageid: <1317476639.29.0.288812849627.issue13077@psf.upfronthosting.co.za>
2011-10-01 13:43:58etuardulinkissue13077 messages
2011-10-01 13:43:58etuarducreate