| Start |
|---|
| Global Interpreter Lock Python multithreading performance can often suffer due to the Global Interpreter Lock (opens new window). In short, even though you can have multiple threads in a Python program, only one bytecode instruction can execute in parallel at any one time, regardless of the number of CPUs. As such, multithreading in cases where operations are blocked by external events - like network access - can be quite effective: Note that even though each However, multithreading in cases where intensive computations are being done in Python code - such as a lot of computation - does not result in much improvement, and can even be slower than running in parallel: In the latter case, multiprocessing can be effective as multiple processes can, of course, execute multiple instructions simultaneously: |
| Running in Multiple Threads Use |
| Running in Multiple Processes Use |
| Sharing State Between Threads As all threads are running in the same process, all threads have access to the same data. However, concurrent access to shared data should be protected with a lock to avoid synchronization issues. |
| Sharing State Between Processes Code running in different processes do not, by default, share the same data. However, the |
Read Article
https://develop.horje.com/learn/1434/reference