You called sys.stderr.flush() after this time of writing to sys.stderr, but not the first.  Do you need to call it after the first time as well or is this flush superfluous?