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 - Python Tutorial
From the course: Python Parallel and Concurrent Programming Part 1
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
Thread vs. process4m 35s
-
Concurrent vs. parallel execution4m 53s
-
Global interpreter lock: Python demo4m 35s
-
Multiple threads: Python demo6m
-
Multiple processes: Python demo5m 42s
-
Execution scheduling3m 38s
-
Execution scheduling: Python demo2m 42s
-
Thread lifecycle3m 35s
-
Thread lifecycle: Python demo5m 38s
-
Daemon thread2m 48s
-
Daemon thread: Python demo2m 29s
-
-
-
-
-