Python Async is a Mess

Especially for Absolute Beginners

Today a beginning student asked me, “Mr. Rob, how do I add a countdown timer to my Python program so I can make a time limit on the user’s answer?”

A pretty straightforward use case that should get a pretty clear answer in any modern language, but not for Python. Even though asyncio is an official part of the standard library added in 3.4 the code that uses it is anything but easy or intuitive, (google it for yourself), so much for Python ease of use as a justification for teaching it to beginners.

Meanwhile, in JavaScript land:

setTimeout( () => alert("Ring!"), 3000 )

And in Go land:

go func() {
time.Sleep(3 * time.Second)
fmt.Println("Ring!")
}()

Having multiple things happening concurrently is a given these days—especially something as simple as an alarm that works on everything. Python simply does not deliver. The asyncio approach borders on ridiculous in comparison.

I’ll continue to post discovers as they organically surface from students raising them. (I’ll never forget the day my entire Java class revolted against Java in the middle, having learned JavaScript and Python before. They asked to learn Go and are still coding in it to this day. It is amazing how much even a beginner can spot bad language design.)