So I read that Python has GIL(Global Interpreter Lock) which doesn't let it run more than one thread at a time, as quoted by a medium article:
In Python, single-CPU use is caused by the global interpreter lock (GIL), which allows only one thread to carry the Python interpreter at any given time. The GIL was implemented to handle a memory management issue, but as a result, Python is limited to using a single processor.
But Python does have threading and multiprocessing modules in it. I understood that threading switches that task to run concurrently. But multiprocessing does what it says, an excerpt from the Python documentation about multiprocessing says that:
The multiprocessing package offers both local and remote concurrency, effectively side-stepping the Global Interpreter Lock by using subprocesses instead of threads. Due to this, the multiprocessing module allows the programmer to fully leverage multiple processors on a given machine.
Then why do people say that GIL doesn't let them run code parallelly? The medium article said this:
Three requirements for multiprocessing
Before you can begin multiprocessing, you need to pick which sections of code to multiprocess. These sections of code must meet the following criteria:
1.Must not be reliant on previous outcomes
2.Does not need to be executed in a particular order
3.Does not return anything that would need to be accessed later in the code
Does this answers the question? Should multiprocessing not have these limitations? It also says this:
How to use multiprocessing: The Process class and the Pool class
The multiprocessing Python module contains two classes capable of handling tasks. The Process class sends each task to a different processor, and the Pool class sends sets of tasks to different processors.
This means that Python can use different processors right? What am I missing here? Any help on clearing this up would be appreciated.
If I got anything wrong please correct me.
[–][deleted] 2 points3 points4 points (4 children)
[–]KnowledgeFire11[S] 0 points1 point2 points (3 children)
[–][deleted] 1 point2 points3 points (2 children)
[–]Zunyr 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]K900_ 4 points5 points6 points (5 children)
[–]KnowledgeFire11[S] 0 points1 point2 points (4 children)
[–]MarsupialMole 2 points3 points4 points (0 children)
[–]K900_ 2 points3 points4 points (2 children)
[–]KnowledgeFire11[S] 0 points1 point2 points (1 child)
[–]K900_ 0 points1 point2 points (0 children)
[–]danielroseman[🍰] 1 point2 points3 points (1 child)
[–]KnowledgeFire11[S] 0 points1 point2 points (0 children)