Simon Willison’s Weblog

Subscribe

13 items tagged “concurrency”

2024

Free-threaded CPython is ready to experiment with! The Python 3.13 beta releases that include a "free-threaded" version that removes the GIL are now available to test! A team from Quansight Labs, home of the PyData core team, just launched py-free-threading.github.io to help document the new builds and track compatibility with Python's larger ecosystem.

Free-threading mode will not be enabled in Python installations by default. You can install special builds that have the option enabled today - I used the macOS installer and, after enabling the new build in the "Customize" panel in the installer, ended up with a /usr/local/bin/python3.13t binary which shows "Python 3.13.0b3 experimental free-threading build" when I run it.

Here's my TIL describing my experiments so far installing and running the 3.13 beta on macOS, which also includes a correction to an embarrassing bug that Claude introduced but I failed to catch!

# 12th July 2024, 11:42 pm / concurrency, gil, python, threading

2023

Real Multithreading is Coming to Python—Learn How You Can Use It Now (via) Martin Heinz provides a detailed tutorial on trying out the new Per-Interpreter GIL feature that’s landing in Python 3.12, which allows Python code to run concurrently in multiple threads by spawning separate sub-interpreters, each with their own dedicated GIL.

It’s not an easy feature to play with yet! First you need to compile Python yourself, and then use APIs that are generally only available to C code (but should hopefully become available to Python code itself in Python 3.13).

Martin’s workaround for this is ingenious: it turns out the Python test.support package provides utility functions to help write tests against interpreters, and Martin shows how to abuse this module to launch, run and cleanup interpreters using regular Python code.

He also demonstrates test.support.interpreters.create_channel(), which can be used to create channels with receiver and sender ends, somewhat similar to Go.

# 15th May 2023, 7:42 pm / concurrency, gil, go, python

2022

PEP 554 – Multiple Interpreters in the Stdlib: Shared data (via) Python 3.12 hopes to introduce multiple interpreters as part of the Python standard library, so Python code will be able to launch subinterpreters, each with their own independent GIL. This will allow Python code to execute on multiple CPU cores at the same time while ensuring existing code (and C modules) that rely on the GIL continue to work.

The obvious question here is how data will be shared between those interpreters. This PEP proposes a channels mechanism, where channels can be used to send just basic Python types between interpreters: None, bytes, str, int and channels themselves (I wonder why not floats?)

# 20th September 2022, 1:25 am / concurrency, pep, python

2021

The GIL and its effects on Python multithreading (via) Victor Skvortsov presents the most in-depth explanation of the Python Global Interpreter Lock I’ve seen anywhere. I learned a ton from reading this.

# 29th September 2021, 5:23 pm / concurrency, gil, python, threading

2012

Can Scala gain wider usage than Java any time soon?

No, because Scala is harder to master than Java.

[... 54 words]

What server do I need to handle 1000+ users simultaneously while they can post messages, upload pictures, and other similar stuff on a website based on PHP and mySQL?

You don’t need to handle 1,000 users simultaneously: you need to build something and ship it and start the process of discovering what you can build that will attract that many users. Seriously: don’t even start worrying about that kind of scale until you know you’re going to need it.

[... 138 words]

2010

Distributed lock on top of memcached. A simple Python context manager (taking advantage of the with statement) that implements a distributed lock using memcached to store lock state: “memcached_lock can be used to ensure that some global data is only updated by one server”. Redis would work well for this kind of thing as well.

# 1st February 2010, 10:15 am / concurrency, contextmanager, locking, memcached, plurk, python, redis, with

2009

dustin’s gomemcached (via) A memcached server written in Go, an experiment by memcached maintainer Dustin Sallings.

# 13th November 2009, 3:13 pm / concurrency, dustinsallings, go, memcached, programming

The Go Programming Language. A brand new systems programming language, designed by Robert Griesemer and Unix/Plan 9 veterans Rob Pike and Ken Thompson and funded by Google. Concurrency is supported by lightweight communicating processes called goroutines. “It feels like a dynamic language but has the speed and safety of a static language.”

# 11th November 2009, 7 am / concurrency, go, google, goroutines, kenthompson, plan9, programming, robert-griesemer, rob-pike, unix

Testing Django Views for Concurrency Issues. Neat decorator for executing a Django view under high concurrency in your unit tests, to help spot errors caused by database race conditions that should be executed inside a transaction.

# 27th May 2009, 10:01 am / concurrency, django, python, raceconditions, testing, threadsafety

A Curious Course on Coroutines and Concurrency. David Beazley’s sequel to last year’s mind-expanding “Generator Tricks for System Programmers”, perfect for if you’ve ever puzzled over what exactly you can use Python’s generator-based coroutine support for.

# 24th April 2009, 10:58 am / concurrency, coroutines, david-beazley, generators, python

django-springsteen and Distributed Search. Will Larson’s Django search library currently just talks to Yahoo! BOSS, but is designed to be extensible for other external search services. Interestingly, it uses threads to fire off several HTTP requests in parallel from within the Django view.

# 25th February 2009, 10:28 pm / concurrency, django, djangospringsteen, http, python, search, threads, will-larson, yahooboss

2007

Mac OS X Leopard: Multicore. “... NSOperation, a breakthrough new API that optimizes applications for the world of multicore processing.”

# 11th June 2007, 11:02 pm / concurrency, leopard, multicore, nsoperation, osx