Python parallel threads in 3.13 GIL-less environment

673 views Asked by At

I was working on a python program and I was attempting to implement some parallel processing to improve the runtime for a cpu-bound task that don't write to the same memory location. I've had some experience with using the multiprocessing library since using threading in past projects ran slower due to the GIL. From my understanding the GIL was removed in 3.13. Does this mean the threading module should work faster than multiprocessing for my use-case now by default without any of the GIL workarounds? If this is not the case, are there any libraries that have been developed for the non-GIL 3.13 that I can use for multithreading?

I tried looking at the PEPs for 3.13 and the removing of GIL (703), but I'm not totally able to understand how it affects existing libraries.

1

There are 1 answers

0
OM222O On

Removal of GIL is a slow and multi-release schedule. There will most likely be 2 releases of Python (with/without GIL enabled out of the box) while they roll out the fixes required like immortal objects (which is in 3.12), changes to reference counting, etc. If you need to bypass GIL and you're worried about performance, read up on Cython. It allows creating fast C++ extensions AND lets you bypass the GIL as long as you're working with things like memory views (Python objects can't be accessed when you release the GIL).