Use detach for TextIOWrapper.  See http://bugs.python.org/issue21363