From the course: Python Parallel and Concurrent Programming Part 1

Unlock the full course today

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

Execution scheduling: Python demo

Execution scheduling: Python demo - Python Tutorial

From the course: Python Parallel and Concurrent Programming Part 1

Start my 1-month free trial

Execution scheduling: Python demo

- [Instructor] To demonstrate how scheduling can impact execution we've written this Python program that creates two threads named Barron and Olivia that continuously chop vegetables for about one second. In the vegetable_chopper function beginning on line 9, the program uses the threading module's current_thread and getName methods to retrieve the name of the current thread and then it initializes a local variable to count the number of vegetables this thread chops. The while loop on line 12 will execute as long as the chopping variable that I initialize on line seven is True. And within each loop iteration it'll print a message and increment the value of the local vegetable_count variable. Finally after the while loop finishes, the vegetable_chopper function prints out how many total vegetables it chopped on line 15. Down in the main section on lines 18 and 19, we create and start two threads to execute the…

Contents