守护线程在 Python 3.5.1 中有何用处?

How are daemon threads useful in Python 3.5.1?

在浏览线程对象的 python 文档时,它有一个关于守护线程的注释,其中说:

Daemon threads are abruptly stopped at shutdown. Their resources (such as open files, database transactions, etc.) may not be released properly. If you want your threads to stop gracefully, make them non-daemonic and use a suitable signalling mechanism such as an Event.

那么我们为什么要使用它们呢?

Python 尝试在退出时加入非守护线程。如果您没有实施终止它们的机制,python 将挂起。令人讨厌的是,ctrl-C 通常不起作用,您必须在外部终止程序。