fix line-buffering output with Python 3