Daemon threads are a regular source of pain in core development and have been for years.  I’d like to get rid of them.  The impact on the Python com

Getting Rid of Daemon Threads

submited by
Style Pass
2024-10-24 15:30:06

Daemon threads are a regular source of pain in core development and have been for years. I’d like to get rid of them. The impact on the Python community is the deciding factor; I suspect low impact but may be wrong. Your feedback will help.

Existing users of daemon threads can generally update their code to get the same effect from non-daemon threads. See gh-125857 for examples.

Daemon threads have been a part of the threading module since it was added in 1998 (Python 1.5.1). (The low-level “thread” module was added in 1992, without daemon threads.)

Why were daemon threads part of that initial API? Mostly because Java threads had them–the threading module was essentially copied from Java’s threading API. Unfortunately, in the case of daemon threads, we eventually learned that what made sense for Java did not make sense for Python.

Note that in Python 3.12, interpreters created using Py_NewInterpreterFromConfig() default to disallowing daemon threads. In 3.14, those created by InterpreterPoolExecutor never allow daemon threads. Likewise for the API in PEP 734.

Leave a Comment