The answer is "Yes, But..."
But cPython cannot when you are using regular threads for concurrency.
You can either use something like multiprocessing
, celery
or mpi4py
to split the parallel work into another process;
Or you can use something like Jython or IronPython to use an alternative interpreter that doesn't have a GIL.
A softer solution is to use libraries that don't run afoul of the GIL for heavy CPU tasks, for instance numpy
can do the heavy lifting while not retaining the GIL, so other python threads can proceed. You can also use the ctypes
library in this way.
If you are not doing CPU bound work, you can ignore the GIL issue entirely (kind of) since python won't aquire the GIL while it's waiting for IO.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…