These days virtually every PC, laptop, tablet and smartphone has a multi-core processor. But can Python make use of this additional processing power?
Well, the good news is that Python's core library has full support for threading. So, each computational activity can be assigned its own dedicated process thread. This is particularly useful in PyGame programs where sprites move around independently.
Unfortunately, the bad news is that these threads cannot be run in parallel. And here's why
It's all down to the Python interpreter which internally uses a Global Interpreter Lock (GIL). The GIL can only execute one Python byte-code instruction at a time - even when running on a modern multi-core processor.
However, all is not lost.
The Parallel Python Project has developed a module which overcomes this GIL limitation. Under the covers the
pp module uses a combination of processes and inter-process communications (IPC) to implement parallel computation.
So, pop over to the Parallel Python Project website to see examples of the
pp module API in action and read the documentation.
An alternative solution is provided by the PyPar project. Originally hosted at Google project, Pypar is an efficient but easy-to-use module that provides parallel execution through message passing, via the message passing interface standard MPI.
A post from my Learn Python on the Raspberry Pi tutorial.