Handle case where fileno() raises UnsupportedOperation on Python 3