From the course: Python Parallel and Concurrent Programming Part 1
Unlock the full course today
Join today to access over 22,700 courses taught by industry experts or purchase this course individually.
Thread lifecycle: Python demo - Python Tutorial
From the course: Python Parallel and Concurrent Programming Part 1
Thread lifecycle: Python demo
- [Instructor] To demonstrate the life cycle of a Python thread, from creation to termination, we've created this example program, which recreates the interactions between Olivia and me, where I spawned her as a second thread to help slice sausages to make soup. Now there are two ways to create a thread and specify its activity in Python. In the previous Python examples, we put the code for our thread to execute into a function. And then passed that function to the thread constructor method as a callable object using the target parameter. The other way to create a thread in Python is to define a custom subclass that inherits from the thread class and overrides its run method. That second approach is what we've done with the class named ChefOlivia on line seven. It inherits from threading.Thread and overrides two of its methods, init and run. These are the only two methods you should override from the thread…
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
-
(Locked)
Concurrent vs. parallel execution4m 53s
-
Global interpreter lock: Python demo4m 35s
-
(Locked)
Multiple threads: Python demo6m
-
(Locked)
Multiple processes: Python demo5m 42s
-
(Locked)
Execution scheduling3m 38s
-
(Locked)
Execution scheduling: Python demo2m 42s
-
(Locked)
Thread lifecycle3m 35s
-
(Locked)
Thread lifecycle: Python demo5m 38s
-
(Locked)
Daemon thread2m 48s
-
(Locked)
Daemon thread: Python demo2m 29s
-
-
-
-
-