FORKS? POOLS? ASYNC? Solving Wordle with Python’s concurrency tools
I’ve played Wordle most days since late 2021. Maybe you have too? One thing I wonder after solving the puzzle for the day is whether I made a bad choice of words. Should I have chosen SMASH, or STASH? Just how lucky was I to solve a puzzle?
This talk will explore how to implement a Wordle statistics bot using Python's concurrent processing tools. No spoilers, I promise.
See this talk and many more by getting your ticket to PyCon AU now!
I want a ticket!I’ve played Wordle most days since late 2021. Maybe you have too? One thing I wonder after solving the puzzle for the day is whether I made a bad choice of words. Should I have chosen SMASH, or STASH? Just how lucky was I to solve a puzzle?
The good news is that writing a bot to solve Wordle — or, if you’d prefer, give a statistical review of how well you played — is quite easy to do, but the first implementation you might write in Python will probably be quite slow: there’s lots of words to choose from, and figuring out which word might be a good guess depends on comparing against a lot of other words.
The good news is that these sorts of tests are things that can be sped up by parallel processing, and Python has some tools that can help with this.
In this talk, we’ll discuss a simplified implementation of the algorithm used by the New York Times’ Wordlebot, and then we’ll look at speeding it up using Python’s concurrency tools. We’ll look at making small changes to use the concurrent.futures
package, to see the performance difference between thread pools and process pools; we’ll look at what structural changes you might make to use Python’s async
functions; and we’ll finish off by looking at the nogil
branch of Python to see how this impacts our performance.
This talk is a fun way to look at how Python performs at concurrent processing tasks, and what future development in Python might have for problems like this one. And while there’ll be a small amount of maths involved, it shouldn’t be enough to scare you off.
And nothing in this talk will spoil today’s Wordle. Or tomorrow’s. I promise.
Christopher Neugebauer is an Australian developer, speaker, and serial community conference organiser, who presently lives in the United States.
He serves as a Director of the Python Software Foundation, and is co-organiser of the acclaimed North Bay Python conference, a boutique one-track conference run in unusual venues — include an old vaudeville theatre, and more recently a barn on a farm — in Petaluma, California.
Christopher is also a contributor on the open source Pants build system, helping make Python’s testing, correctness, and style tools accessible and fast for developers, no matter how big their codebase.