From the course: Complete Guide to Parallel and Concurrent Programming in Python

Unlock the full course today

Join today to access over 24,900 courses taught by industry experts.

Execution scheduling: Python demo

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 7 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 vegetable_chopper function, and we pass in the strings Barron and Olivia to…

Contents