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 - Python Tutorial
From the course: Complete Guide to Parallel and Concurrent Programming in Python
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…
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
-
(Locked)
Global interpreter lock: Python demo4m 35s
-
(Locked)
Multiple threads: Python demo5m 52s
-
(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
-
-
-
-
-
-
-
-
-
-
-