Free-threaded CPython is ready to experiment with
CPython 3.13 introduces free-threading to enhance performance by allowing parallel threads without the GIL. Challenges like thread-safety and ABI compatibility are being addressed for future adoption as the default build.
Read original articleA new experimental feature in CPython 3.13 called free-threading allows running multiple threads in parallel within the same interpreter by disabling the global interpreter lock (GIL). This change aims to improve performance, especially in multi-threaded scenarios, by utilizing multiple CPU cores effectively. However, implementing free-threading poses challenges related to thread-safety and ABI incompatibility between default and free-threaded CPython builds. Issues like intermittent failures in libraries such as NumPy and PyWavelets highlight the complexity of ensuring thread-safety in the ecosystem. Despite the challenges, efforts are underway to address these issues, with a focus on compatibility and performance improvements. The team behind this initiative is working on various projects to support free-threaded CPython, with plans to release compatible wheels on PyPI for experimentation. The ultimate goal is to make free-threaded CPython the default build in the future, with ongoing efforts to document lessons learned and facilitate community contributions to support this transition.
Related
What's up Python? Django get background tasks, a new REPL, bye bye gunicorn
Several Python updates include Django's background task integration, a new lightweight Python REPL, Uvicorn's multiprocessing support, and PyPI blocking outlook.com emails to combat bot registrations, enhancing Python development and security.
Python Modern Practices
Python development best practices involve using tools like mise or pyenv for multiple versions, latest Python version, pipx for app running. Project tips include src layout, pyproject.toml, virtual environments, Black, flake8, pytest, wheel, type hinting, f-strings, datetime, enum, Named Tuples, data classes, breakpoint(), logging, TOML config for efficiency and maintainability.
Summary of Major Changes Between Python Versions
The article details Python updates from versions 3.7 to 3.12, highlighting async/await, Walrus operator, Type hints, F-strings, Assignment expressions, Typing enhancements, Structural Pattern Matching, Tomllib, and useful tools.
Instrumenting Python GIL with eBPF
Python's Global Interpreter Lock (GIL) simplifies memory management but limits performance in multi-threaded, CPU-bound programs. Coroot explains GIL impact and measurement using eBPF, offering insights and automation in version 1.3.1 for Python users.
[x] Async.
[x] Optional static typing.
[x] Threading.
[ ] JIT.
[ ] Efficient dependency management.
This is a big fundamental and (in many cases breaking) change, even if it's "optional".
Meanwhile what takes the crown? - Single threaded python.
(Well, ok Rust looks like it's taking first place where you really need the speed and it does help parallelism without requiring absolute purity)
Is there a cibuildwheel / CI check for free-threaded Python support?
Is there already a reason not to have Platform compatibility tags for free-threaded cpython support? https://packaging.python.org/en/latest/specifications/platfo...
Is there a hame - a hashtaggable name - for this feature to help devs find resources to help add support?
Can an LLM almost port in support for free-threading in Python, and how should we expect the tests to be insufficient?
"Porting Extension Modules to Support Free-Threading" https://py-free-threading.github.io/porting/
[1] "Python 3 "Wall of Shame" Becomes "Wall of Superpowers" Today" https://news.ycombinator.com/item?id=4907755
(Edit)
Compatibility status tracking: https://py-free-threading.github.io/tracking/
I'd love to see a more fluid model between the two -- E.G. if I'm doing a "gather" on CPU-bound coroutines, I'm curious if there's something that can be smart enough to JIT between async and multithreaded implementations.
"Oh, the first few tasks were entirely CPU-bound? Cool, let's launch another thread. Oh, the first few threads were I/O-bound? Cool, let's use in-thread coroutines".
Probably not feasible for a myriad of reasons, but even a more fluid programming model could be really cool (similar interfaces with a quick swap between?).
-Episode 2: Removing the GIL[1]
-Episode 12: A Legit Episode[2]
[1]https://www.youtube.com/watch?v=jHOtyx3PSJQ&list=PLShJCpYUN3...
[2]https://www.youtube.com/watch?v=IGYxMsHw9iw&list=PLShJCpYUN3...
What about simple operations like incrementing an integer? IIRC this is currently thread-safe because the GIL guarantees each bytecode instruction is executed atomically.
Really excited about this.
With it, the single-threaded case is slower.
Related
What's up Python? Django get background tasks, a new REPL, bye bye gunicorn
Several Python updates include Django's background task integration, a new lightweight Python REPL, Uvicorn's multiprocessing support, and PyPI blocking outlook.com emails to combat bot registrations, enhancing Python development and security.
Python Modern Practices
Python development best practices involve using tools like mise or pyenv for multiple versions, latest Python version, pipx for app running. Project tips include src layout, pyproject.toml, virtual environments, Black, flake8, pytest, wheel, type hinting, f-strings, datetime, enum, Named Tuples, data classes, breakpoint(), logging, TOML config for efficiency and maintainability.
Summary of Major Changes Between Python Versions
The article details Python updates from versions 3.7 to 3.12, highlighting async/await, Walrus operator, Type hints, F-strings, Assignment expressions, Typing enhancements, Structural Pattern Matching, Tomllib, and useful tools.
Instrumenting Python GIL with eBPF
Python's Global Interpreter Lock (GIL) simplifies memory management but limits performance in multi-threaded, CPU-bound programs. Coroot explains GIL impact and measurement using eBPF, offering insights and automation in version 1.3.1 for Python users.