Search code examples
pythonmultithreadingpython-3.xmultiprocessingcpython

Does multiprocessing module fix CPython multi-core usage?


In CPython, threading module doesn't utilise multiple cores because it uses global interpreter lock. However I recently found multiprocessing module from standard library which is said to sidestep the GIL. So I think with that module it is possible to utilise multiple core properly in CPython, but I wonder if I'm right.

I need to write an app which requires good utilisation of multiple cores, but it's not that performance critical so I could write it in Python, but I need to know whether this module will allow me to use multiple cores?


Solution

  • The multiprocessing library uses child processes; these each run in their own Python interpreter.

    The OS can and will schedule these process across multiple processes and cores, yes. Because each child process is a separate Python interpreter process, the GIL does not interfere.