GIL Become Optional in Python 3.13
In Python 3.13, a feature will be added with the name "free threaded build" that will allow coders to enable or disable GIL (Global Interpreter Lock) to empower multi-threaded tasks in Python

GIL or Global Interpreter Lock can be disabled in Python version 3.13. This is currently experimental.
What is GIL? It is a mechanism used by the CPython interpreter to ensure that only one thread executes the Python bytecode at a time.
An Experimental Feature
Python 3.13 brings major new features compared to Python 3.12 and one of them is free-threaded mode, which disables the Global Interpreter Lock, allowing threads to run more concurrently.
This is an experimental feature and if you want to try it, you can download the beta version of Python 3.13 from here.
At the time of installation, check the option “free threaded binaries(experimental)” to get the feature in Python.
Making GIL Optional in Python 3.13
The GIL will be disabled when you configure the Python with the --disable-gil option which is nothing but a build configuration (free threading build) at the time of installation.
This will allow optionally enabling and disabling GIL using the environment variable PYTHON_GIL which can be set to 1 and 0 respectively.
It will also provide a command-line option -X gil which can also be set to 0 (disable) and 1 (enable).
# v3.13
# GIL disabled
python3 -X gil=0 sample.py
# GIL enabled
python3 -X gil=1 sample.pyWe can also check if the current interpreter is configured with the free threading build (--disable-gil) by using the following code.
import sysconfig
print(sysconfig.get_config_var("Py_GIL_DISABLED"))If we run this, we’ll get either 0 which means GIL is enabled, or 1 which means GIL is disabled.
With this, we’ll also get a function that can be used to check if GIL is disabled in the running process.
import sys
sys._is_gil_enabled() # returns a boolean valueCheck out » GIL Become Optional in Python 3.13 for a detailed comparison of GIL Vs No GIL.

