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.
Multiple processes: Python demo - Python Tutorial
From the course: Python Parallel and Concurrent Programming Part 1
Multiple processes: Python demo
- To leverage multiple processors, and to achieve true parallel execution in python, rather than structuring our program to use multiple threads, we'll need to use multiple processes. Fortunately, Python's multiprocessing package makes that pretty straight forward, because it provides an API for spawning additional processes that looks very similar to the threading module. To demonstrate just how similar they are, I'll modify the code from the previous example, which created several threads running the CPU waster function to use several processes instead. First, I'll need to import the multi`processing module. And, since that's a long word, I'll rename it to mp for short. Next, on line 21, I'll replace the threading modules thread class with the multiprocessing packages process class, and finally, when using the multiprocessing package to spawn additional processes, it's important to enclose the main body of the program,…
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
-
-
-
-
-