Python 3.12–3.13 — JIT and Free-Threading (2023–2024)
Python · History & Evolution · Run with python3
Explanation
Python 3.12 (Oct 2023) improved f-strings (arbitrary expressions inside), added `@override` for type checkers, and removed the long-deprecated `distutils`. Python 3.13 (Oct 2024) shipped two experimental features that could reshape Python's performance story: an experimental JIT compiler (copy-and-patch, enabled with `--enable-experimental-jit`) and an optional free-threaded mode that disables the GIL (PEP 703, enabled with `--disable-gil` at build time, usable per-interpreter via `python3.13t`).
Real-World Scenario
A CPU-bound image processing task using `multiprocessing` had to fork 8 worker processes (heavy memory). With Python 3.13 free-threaded mode, the same task can run 8 threads sharing the same address space — dramatically reducing memory usage and improving cache locality.
Quick Snippet
import sys
# Python 3.12+ f-string: arbitrary expressions allowed
items = ["a", "b", "c"]
result = f"{'|'.join(items)}" # Previously a SyntaxError
print(result) # a|b|c
# Check if running in free-threaded mode (3.13+)
if hasattr(sys, "_is_gil_enabled"):
print(f"GIL enabled: {sys._is_gil_enabled()}")
else:
print(f"Python {sys.version_info.major}.{sys.version_info.minor}")Full Example
# Compile: python3 python313_features.py
# Output:
# a|b|c
import sys
# Python 3.12+ f-string: arbitrary expressions (same quote type) allowed
items = ["a", "b", "c"]
result = f"{'|'.join(items)}"
print(result)
print(f"Python {sys.version_info.major}.{sys.version_info.minor}")
# Free-threaded check (Python 3.13+)
if hasattr(sys, "_is_gil_enabled"):
gil = sys._is_gil_enabled()
print(f"GIL enabled: {gil}")
if not gil:
print("Running in free-threaded mode (python3.13t)")
else:
print("GIL: always enabled on this Python version")
python3 python313_features.py