Skip to content Skip to sidebar Skip to footer

Python Threads Are Not Improving Speed

In order to speed up a certain list processing logic, I wrote a decorator that would 1) intercept incoming function call 2) take its input list, break it into multiple pieces 4) pa

Solution 1:

Yes, when your threads are doing CPU-bound work implemented in Python (not by, say, C extensions which can release the GIL before and after marshalling/demarshalling data from Python structures), the GIL is a problem here.

I'd suggest using a multiprocessing model, a Python implementation that doesn't have it (IronPython, Jython, etc), or a different language altogether (if you're doing performance-sensitive work, there's no end of languages nearly as fluid as Python but with considerably better runtime performance).


Solution 2:

Alternatively you can redsign and start all parallel Code in subprocesses.

You need worker-threads which start a subprocess for calculation. Those subprocesses can run really parallel.


Post a Comment for "Python Threads Are Not Improving Speed"