You are currently viewing How to Disable GIL in Python 3.13?

How to Disable GIL in Python 3.13?

The official version of Python 3.13 has been released by the Python organization, and with this, you get many major changes.

One of the major changes we get is making GIL (Global Interpreter Lock) optional in Python 3.13.

In this article, you’ll see how you can disable GIL in Python 3.13 to make multi-threaded programs faster.

Disable GIL in Python 3.13

First, download the official Python 3.13 on your local machine. Then proceed to install the Python executable file.

Follow the steps just as you install any Python version, you will see a step in which you are asked to choose the advanced installation options.

Advance free-threaded option

Now select the checkbox appearing at the end, this will install the different executable Python build with the name python3.13t or python3.13t.exe.

Enable free-threaded option

This will allow you to optionally disable or enable GIL in the runtime. Now proceed to install the setup.

After completing the setup for Python 3.13, if you look at the file location of Python 3.13, you will see that you also got a different Python build called python3.13t.

Free-threaded CPython

If you remember that “free-threaded binaries” mode was marked “experimental”, this means that you don’t get GIL disabled by default.

But how do I disable GIL? Python organization provided a different CPython build which is also called “Free-threaded CPython”.

Free-threaded CPython will help you disable GIL. Let’s see how to do it.

Let’s say, you have a Python script and you want it to run with GIL disabled. You can use the following command.

This CPython build comes with GIL disabled by default.

Practical

I have the following Python script (main.py) that runs a multi-threaded task and calculates the time taken to complete the execution.

Now, we’ll run this script with and without free-threaded CPython.

With GIL enable (without free-threaded CPython)

Python running with GIL enabled

With GIL disable (with free-threaded CPython)

Python running with GIL disabled

That’s all for now.

Keep Coding✌✌