It turns out that clearing stdin is made easy with Python’s
We can use the that module’s functionality to poll input streams to test
whether I/O operations will block program flow. If you’re just interested in
the code, here’s the Gist. Otherwise, let’s work through it.