From 7576aae3448f3dc4396d740d9025f30866f8e9df Mon Sep 17 00:00:00 2001 From: Daniel Garcia Moreno Date: Tue, 10 Sep 2024 12:45:35 +0200 Subject: [PATCH] Create 2024-09-11-python313.md --- _posts/2024/2024-09-11-python313.md | 75 +++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 _posts/2024/2024-09-11-python313.md diff --git a/_posts/2024/2024-09-11-python313.md b/_posts/2024/2024-09-11-python313.md new file mode 100644 index 00000000..c8c45b91 --- /dev/null +++ b/_posts/2024/2024-09-11-python313.md @@ -0,0 +1,75 @@ +--- +author: Daniel GarcĂ­a Moreno +date: 2024-09-11 08:00:00+20:00 +layout: post +license: CC-BY-SA-3.0 +slug: python313 +title: Python 3.13, with and without GIL +image: /wp-content/uploads/2020/09/pythonlogo.png +categories: +- Announcements +- Tumbleweed +- openSUSE +tags: +- Python +- openSUSE +- SUSE +- Developers +- Open Source +--- + +Python 3.13 RC2 is now available in Tumbleweed. This new version of +the Python interpreter will be released in October 2024. + +There's [a lot of changes](https://www.python.org/downloads/release/python-3130rc2/) +and new features in 3.13, but we're also bringing exiting experimental +features in Tumbleweed. + +### Experimental JIT compiler + +The default (`python313`) build has the flag +`--enable-experimental-jit=yes-off`. This means that if you want to +use this [experimental JIT](https://docs.python.org/3.13/whatsnew/3.13.html#an-experimental-just-in-time-jit-compiler) +you can enable with a environment variable: + +``` +$ PYTHON_JIT=1 python313 +``` + +You can find more information about the JIT compiler and how can this +improve the performance in the +[PEP-744](https://peps.python.org/pep-0744/). + +### Free threaded CPython (no GIL) + +With this new version of Python interpreter there's an option to build +without the famous [Global Interpreter Lock](https://docs.python.org/3.13/whatsnew/3.13.html#free-threaded-cpython), +aka GIL. This is a really experimental feature, but why not have this +on Tumbleweed? So we decided to build also this new version with a new +package `python313-nogil`. + +This new package is an isolated interpreter, so you can install +without conflicts with `python313`. The package is building with the +`--disable-gil` option and it provides the `/usr/bin/python3.13t` +binary. It uses by default `/usr/lib/python3.13t/site-packages` for +third-party libs, so with the default configuration it won't use any +python 3.13 module. + +This means that now you can use `threading.Thread` in the Python +interpreter and it will be actual threads, so at the end using threads +with `python3.13t` interpreter should be a lot faster. + +There's no packages for this interpreter in Tumbleweed, at this +moment. So if you want to use third party libraries you should use +virtualenv and pip for that: + +``` +$ python3.13t -m venv free-threaded-env +$ source free-threaded-env/bin/activate +(free-threaded-env) $ pip install requests +(free-threaded-env) $ python3 +Python 3.13.0rc2 experimental free-threading build (main, Sep 07 2024, 16:06:06) [GCC] on linux +Type "help", "copyright", "credits" or "license" for more information. +>>> import sys; sys._is_gil_enabled() +False +```