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

Thread lifecycle: Python demo - Python Tutorial

From the course: Python Parallel and Concurrent Programming Part 1

Start my 1-month free trial

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…

Contents