Python apparently uses fdopen() and _get_osfhandle() to determine if file descriptors are sockets or not. This is probably more robust and efficient than our method of divining things from random error codes.
Need to check how wine behaves though, as that has been a large source of issues.