Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • Still this issue with python 3 ? There is no clear information regarding these "bizarre exceptions" in the documentation. Commented Jul 19, 2011 at 15:53
  • 6
    From Joe's blog post: "Update June 2015: This is Python bug 1856. It was fixed in Python 3.2.1 and 3.3, but the fix was never backported to 2.x. (An attempt to backport to the 2.7 branch caused another bug and it was abandoned.) Daemon threads may be ok in Python >= 3.2.1, but definitely aren’t in earlier versions." Commented Apr 11, 2016 at 12:19
  • 1
    I'd like to share here my experience: I had a function spawned as Thread multiple times. Inside of it, I had an instance of Python logging and I expected that, after finishing the Thread, all objects (File Descriptors for each Thread/Function), would be destroyed. At the end of my program, I saw many outputs like IOError: [Errno 24] Too many open files:. With lsof -p pid_of_program, I discovered that the FDs were open, even tough the Thread/Functions have finished their jobs. Workaround? Removing the log handler at the end of the function. So daemonic Threads, are untrustworthy... Commented Sep 3, 2019 at 14:42
  • That's odd. If I don't use daemon=True and if I interrupt the process which spawned the Threads, I see that the Threads are still running. The same doesn't happens when this flag is set, the main program and the Threads are all terminated. How would you explain this? If I need to interrupt a program, I want all Threads to terminate as well. Do you know a better approach than this? Thanks. Here's the doc, for further reference: docs.python.org/3/library/threading.html#thread-objects Commented Jul 31, 2020 at 2:46
  • @JoeShaw another comment has this: A bit of advice: Clean shutdown is easy to get wrong when threads and synchronization are involved - if you can avoid it, do so. Use daemon threads whenever possible. stackoverflow.com/a/190131/5042169 lol whose suggestion is more correct? Commented Apr 8, 2021 at 7:23