Build Python with GIL Disabled on CentOS 8
July 4, 2023•198 words
Notes:
- This is for fun only, shouldn’t apply to production
- Lots of stuff may not be present during compiling Python from source, programmes run on the resulting Python compilation may break
- Author may not maintain the no-GIL repo for long.
The design of Python on CPython is crazy with the GIL (Global Interpreter Lock). This GIL make the ‘threading’ module of Python all fake, it doesn’t do multithreading at all, just only 1 thread running at a time, swapping around just as async IO.
There’s a project here which is a fork of the original python/cpython
project with altered source code to disabled GIL by default:
https://github.com/colesbury/nogil
Clone the source code:
git clone https://github.com/colesbury/nogil.git python-nogil
Install required modules before compiling Python (on CentOS 8 for example):
sudo dnf install -y gcc gcc-c++ gfortran
openblas
- gfortran openblas are for Scipy
sudo dnf install -y zlib-devel openssl-devel
libffi-devel
openblas-devel lapack-devel
- zlib-devel is required for Python build
- openssl-devel is for Pip
- libffi-devel is for multiple modules installed by Pip
- openblas-devel lapack-devel are for Scipy
Compile and install Python No-GIL (currently 3.9 in Oct 2021), this takes a while, rather quick, maybe a quarter:
cd python-nogil
# We have
./configure
make -j
sudo make install/usr/local/bin/python3
after this.