Search code examples
pythonmultithreadingpython-3.4concurrent.futures

Run python threads on multiple cores


I know that Python 2.7 does not allow one to run multiple threads on different cores, and you need to use the multiprocessing module in order to achieve some degree of concurrency. I was looking at the concurrent.futures module in Python 3.4. Does using a ThreadPoolExecutor allow you to run different threads on different processes, or is it still bound by GIL constraints? If not, is there a way of running threads on different processors using Python 3.4?

For my use case, using multiple processes is absolutely not feasible.


Solution

  • No. ThreadPoolExector is just a class to help with scheduling work on multiple threads. All of the normal thread constraints still apply.

    To clear up some confusion, threads will run on different processors / cores as the operating system chooses, they just won't run concurrently. The exception is that some C based functions release the GIL temporarily while performing actions not needing the lock.