Surprisingly, in sufficiently new versions of python sys.stderr is line buffered, so it might be worth considering that when using it this way.