As it turns out, self.last_message and the call to on_mesage is not an atomic operation (it cannot be) and it is possible to bail out of the wait-for function before they are called.
By checking the result of the on_messages function instead, this is not possible. It also makes the code simpler, because we don't need to check for the None case anymore, nor do we need to ping.