Multi Threading Vs Multi Processing

Before diving into threading and multi processing let’s understand what are them theoretically. If you are in a hurry jump to the concluded points.

Process:

A process is an active program or we can say a program under execution. A process control a block that controls the execution. It is not the program code itself the block contains information about process id, registers, process state etc. Process doesn’t share memory with any other process thus it is called isolated and it also take more time to terminate. A process can create another process inside it called child processes.

Thread:

Thread is just a segment of the process or we can say it is a lightweight process that can be managed by a scheduler. A process can have multiple threads which is contained inside a process. This is called parallelism which helps to increase the performance. Thread take less time to terminate compared to process. Threads shares memory.

So let’s conclude some important points:

  • Thread is spawned inside a process || Process is started independently.
  • Creating and terminating a thread is faster than process.
  • Memory is shared between threads and not in process.

There is one Global Interpreter Lock (GIL) for all threads and one for each process. Below we will demonstrate what is GIL.

Now let’s dive and check for how it can be implement and about the CPU usage of each.

#multiprocessing #python-programming #python3 #multithreading #threading

Understanding - Multi Threading, Multi Processing - Python
2.10 GEEK