MULTI-PROCESSING Vs MULTI-THREADING
Multiprocessing simply refers to the execution of multiple processes or programs at the same time. This is possible when the hardware concerned has more than one processor. This helps in getting more work done in a shorter period of time. Multiprocessing is used when very high speed is required to process a large volume of data. They can save money when compared to a single processor system because the processors can share peripherals and power supplies. Even if one processor fails, the entire work does not halt; it only slows down, thus making it reliable.
When talking about multi-threading, it means that a system executes multiple threads or code segments of a process or program at the same time. Multiple threads of a single process can share the processor in a single processor system or run in parallel in a multiprocessing system. In python, threading allows you to have different parts of the program run concurrently.
In Python, threading allows you to have different parts of your program run concurrently and can thus simplify the entire process. A thread is in general a separate flow of execution. This means that our program will have two things happening at once. But, for most Python implementations the different threads do not actually execute at the same time: they merely appear to.
It is common to think of threading as having two or more different processors running on your program, each one doing an independent task at the same time. The threads may be running on different processors, but they will actually be only running one at a time.
One problem that arises is that, threads use the same memory heap and they can write to the same location in the memory heap which is why the Python interpreter has a default thread-safe mechanism called the “GIL” (Global Interpreter Lock). This prevents conflicts between threads, by executing only one statement at a time (single-threading).
The Global Interpreter Lock (GIL) in Python prevents parallel threads of execution on multiple cores, thus the threading implementation in python is useful mostly for concurrent thread implementation in web-servers. Python Training provided by Spectrum Softtech Solutions will help you grab a successful career in python.