Python: Multiprocessing Vs. Multithreading
<put a cool image here>
MultiThreading is GOOD when:
It is perfect for I/O operations such as web scraping, because the processor is sitting idle waiting for data.
MultiThreading is BAD when:
For CPU intensive processes, there is little benefit to using the threading module.
Mulitprocessing
Multiprocessing allows you to create programs that can run concurrently (bypassing the GIL) and use the entirety of your CPU core.
Since the processes don’t share memory, they can’t modify the same memory concurrently.
The entire memory is copied into each subprocess, which can be a lot of overhead for more significant programs
When to use each:
If your code has a lot of I/O or Network usage, multithreading is your best bet because of its low overhead.
If you have a GUI, use multithreading so your UI thread doesn’t get locked up.
If your code is CPU bound, you should use multiprocessing (if your machine has multiple cores
Comments
Post a Comment