Posts

Showing posts with the label threads

What is difference between multi-threading and multiprocessing?

Image
Multi-threading vs Multiprocessing : The threading module uses threads, the multiprocessing uses processes. The difference is that threads run in the same memory space, while processes have separate memory.This makes it a bit harder to share objects between processes with multiprocessing. Since threads use the same memory, precautions have to be taken or two threads will write to the same memory at the same time. This is what the global interpreter lock is for. Multiprocessing : Pross : Separate memory space Takes advantage of multiple CPUs & cores Avoids GIL limitations for cPython Child processes are interruptible/killable Cons : Inter-process communication (IPC) a little more complicated with more overhead. Larger memory footprint. Multi-threading : Pross : Lightweight - low memory footprint. Shared memory - makes access to state from another context easier. Allows you to easily make responsive UIs. cPython C extension modules that properly releas