PEP 779: Criteria for supported status for free-threaded Python

for 2 I think contextvars — Context Variables — Python 3.13.2 documentation is preferred? (although definitely a module I only became aware of recently). Definitely feels like something that needs broader teaching around.

I’ve been looking at reducing critical sections, system calls, and locking in BufferedIO (Ideas thread / proposal soon™, 3.15 timeline). That would mean a lot less overhead and potentially no userspace / Python locking in read only and write only I/O (stdin, stdout and stderr). I know techniques and have tools like atomics to do what I need in the CPython C internals, but have no idea how I could implement the same thing Python native (ex. _pyio). I know _pyio is contentious but the delta in what can be expressed / capabilities is to me a problem. Ecosystem often grows faster once it’s part of batteries included, but it doesn’t feel like there are basics yet, and definitely not general directions / guidance with patterns for adopting.

Watching the PRs for free threading going through CPython modules, is a lot of often intricate work relying on a lot of systems tools and general systems programming knowledge (ex. ThreadSanitizer, understanding lock contention, etc). All of that is teachable if people really want to learn it, but most Python code I write I really don’t want to think about it. Recently things like cgi vs. http.server module have come up, and I don’t know what the right thing for free threading is, nor how I’d measure why things are getting slower / tools to help me write better code and understand what is happening/why. It’s great to have a range of options, but in terms of “I want a to write simple Python code to handle HTTP requests” I don’t have a clear picture where I need my code to be headed, let alone where I would go from a simple “flask” app. CGI → WSGI I did quite a while ago. Do I do asyncio now? free threading? both at the same time? How do I make sure what performance I had before doesn’t regress? especially in product code bases that often don’t have comprehensive test and performance suites.

TL; DR: I think there needs to be clear paths for why and how maintainers of systems get to free-threading (might not be for a couple more versions), how ongoing app development can adopt it, and how new projects can write simpler/faster code from day one with it. All very solvable, but today both the tools and the education is at the very least not something visible to me.

2 Likes