From the course: Python Parallel and Concurrent Programming Part 1

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Daemon thread: Python demo

Daemon thread: Python demo - Python Tutorial

From the course: Python Parallel and Concurrent Programming Part 1

Start my 1-month free trial

Daemon thread: Python demo

- [Instructor] In this program, to demonstrate a daemon thread, I defined a function called kitchen cleaner on line seven, which represents a periodic background task like garbage collection. The kitchen cleaner uses an infinite while loop to continuously print a message that Olivia cleaned the kitchen once every second. Down in the program's main section, I create and start a new kitchen cleaner thread named Olivia on lines 13 and 14. Then the main thread prints a series of messages that Barron is cooking, which are split up by sleep statements and then finally a message that Barron is done on line 22. Switching over to the console, I'll type python daemon_thread.py. And press enter to run this program. And I see those messages from Barron and Olivia displayed. But after the main thread reaches the end, and prints its final Barron is done message, the program doesn't exit because the kitchen cleaner thread is still…

Contents