Python 3.13: Better interactive shell and finally multithreading without GIL

The new Python release features an interactive command line and allows the global interpreter lock to be deactivated.

listen Print view
Two snakes in the yellow and blue colors of the Python logo, in front of a laptop with Python code

(Image: erstellt mit KI (Dall-E) durch iX)

4 min. read
Contents

Python 3.13 has been released with a slight delay on the home straight. The new interactive shell aims to make development more convenient. In addition, the global interpreter lock can now be deactivated to allow multithreaded applications to run more efficiently. Finally, the new version includes an experimental just-in-time compiler (JIT).

The release was originally planned for October 1, but performance problems with certain workloads required final fine-tuning and an additional release candidate.

Videos by heise

Python 3.13 uses a new interactive shell by default, which has emerged from the PyPy project and offers significantly more convenience than the previous one.

The new REPL (Read Eval Print Loop) allows code blocks from several lines to be edited directly instead of navigating through the command history line by line. Inserting code blocks is now also more convenient: F3 activates the "Paste Mode", which inserts complete content instead of considering the content as finished when there are empty lines, as was previously the case.

The F2 key activates the history browse mode, which removes the characters >>> and ... so that the code can be copied directly. For a better overview, the REPL now offers color syntax highlighting for prompts and tracebacks by default.

Finally, some essential functions such as help and quit are now directly integrated as commands. For example, entering exit terminates the shell instead of displaying the error message that you should call the exit() function or press Ctrl+Z to exit.

If you want to use the old interactive shell instead of the new one or have to for backwards compatibility reasons, you can activate it via the environment variable PYTHON_BASIC_REPL.

In March, after much preparation and discussion, the decision was made to introduce a flag in Python 3.13 to deactivate the Global Interpreter Lock (GIL). The GIL is intended to guarantee thread security by ensuring that only one thread is running at a time. However, Python cannot use the potential of multiprocessor systems or multi-core processors efficiently.

Python 3.13 now introduces the so-called free-threaded mode, which works without a global interpreter lock. The mode is marked as experimental, and the description warns that bugs and significantly degraded single-threaded performance are still to be expected.

For applications without GIL, a suitable binary is available, which is part of the official installation packages for Windows and macOS. Finally, the GIL can be deactivated via the environment variable PYTHON_GIL or the command line parameter -X gil=0

The new just-in-time compiler is also considered experimental. Python is an interpreted language by default: CPython does not translate the source code into machine code, but only into bytecode, which the Python interpreter interprets at runtime. The bytecode in the pyc files is a direct mapping of the source code without optimizations – unlike compiled languages such as C++ or Rust.

Python 3.13 introduces a JIT compiler that compiles the code into machine code at runtime to improve performance. The Christmas Day (December 25, 2023) pull request on GitHub is peppered with a nice, nerdy Christmas poem.

There are also some noteworthy developments in the platforms: The CPython project recognizes three tiers for operating systems with different requirements. With Python 3.13, the mobile operating systems Android and iOS are considered official platforms at the lowest Tier 3. WebAssembly is now in Tier 2 in combination with WASI (WebAssembly System Interface), while the combination with Emscripts has been dropped in the current release.

With the current release, the official support period for the annual Python releases has been extended: from Python 3.13, the releases receive two years of full support, followed by three years of security fixes. Previously, support was provided for one and a half years, followed by three and a half years of security fixes.

Further innovations such as the adjustment to the locals() build-in can be found in the Python documentation.

(rme)

Don't miss any news – follow us on Facebook, LinkedIn or Mastodon.

This article was originally published in German. It was translated with technical assistance and editorially reviewed before publication.