Next up
Continuing in
Asynchronous Programming with Python
This is a preview of subscription content
Your browser needs to be JavaScript capable to view this video
Try reloading this page, or reviewing your browser settings
This part finishes the video with a brief summary.
Keywords
- Asynchronous programming
- python
- threads
- processes
- multi threading
- multi processing
About this video
- Author(s)
- Coen de Groot
- First online
- 22 December 2020
- DOI
- https://doi.org/10.1007/978-1-4842-6582-6_16
- Online ISBN
- 978-1-4842-6582-6
- Publisher
- Apress
- Copyright information
- © Coen de Groot 2020
Related content
Book
- Richard Blewett
- Andrew Clymer
Video
- Coen de Groot
Video Transcript
We have covered quite a lot in this video. Does your code do a lot of rating for input-output, or is it thrashing your CPU with heavy calculations? Use threads for I/O-bound code and processes for CPU-bound code. Threads are lightweight, quick to start, and with little memory overhead. Each process is a complete copy of Python, slow to start and requiring significant additional memory.
If you need fine control, use the threading or multiprocessing libraries and take manual control over the coordination and communication between threads and processes using locks, barriers, semaphores, events, or timers. Workers and queues are an excellent pattern to distribute the work over multiple threads or processes. The concurrent features library makes it very easy to create a pool of workers, submit functions and arguments, or use map to run the same function many times with separate arguments, all handled by a pool of workers.
Use your understanding of multitasking to write a robust code. Make sure you have tests in place and know how to fix any bugs. Using the information from the last part of this video, go ahead. Have fun with multithreading and multiprocessing, and be productive.