You should use a with statement instead of closing both this file descriptors by hand. If _make_binary_stream or os.fdopen doesn't work with `with`, you could use contextlib. See http://pymotw.com/2/contextlib/ for more info.