Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable the GIL in python3.13?

I am excited to experiment with python3.13 with new GIL optional feature. I want to explore the impact of disabling GIL to achieve real multi-threading in python. I want a real world example to compare the python3.13 performance for multi-threading with GIL enabled and disabled.

In the same environment, can i run two python one with GIL and other without GIL?

REF: PEP703

like image 203
ADITYA GUPTA Avatar asked Jun 20 '26 14:06

ADITYA GUPTA


2 Answers

According to the What's new in Python 3.13, you need a new Python binary to test it.

The free-threaded mode requires a different executable, usually called python3.13t or python3.13t.exe.

Using pyenv latest version to install Python, this should give you a virtual environment to test it (in most unix systems):

pyenv install 3.13t-dev
$HOME/.pyenv/versions/3.13t-dev/bin/python3.13t -m venv .venv
source .venv/bin/activate

You can check it with sys._is_gil_enabled()

python -c 'import sys; print(sys._is_gil_enabled())'
# you should get 'False'
like image 76
Caio Salgado Avatar answered Jun 23 '26 02:06

Caio Salgado


Ubunt users can use:

sudo add-apt-repository ppa:deadsnakes
sudo apt-get update
sudo apt-get install python3.13-nogil
like image 41
Dj Mamana Avatar answered Jun 23 '26 02:06

Dj Mamana



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!