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 - Python Tutorial
From the course: Python Parallel and Concurrent Programming Part 1
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…
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
-
-
-
-
-