Force Python to flush to stdout whenever we have an event to print

We want to see events as soon as they come in without waiting on the
output buffer to fill up. Is there a less heavy-handed way to do this?
Merge pull request #12657 from whiteinge/state-event-out-buffer

Force Python to flush to stdout whenever we have an event to print