etuardu <edo...@gmail.com> added the comment:

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.

----------
Added file: http://bugs.python.org/file23283/foo.py

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue13077>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to