New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use fcntl(fd, F_GETFD) to check whether an fd is valid #90073
Comments
is_valid_fd() uses dup() or fstat() to check whether an fd is valid. Both operations are costly. fcntl() with F_GETFD returns the file descriptor flags (e.g. CLOEXEC) and -1 with errno set to EBADF when fd is not an open file descriptor. It's faster than duplicating + closing a fd or calling fstat(). The idea to use fcntl(fd, F_GETFD) is inspired by the patch [1]. According to Stackoverflow [2]:
|
I've created bpo-45919 with a suggested enhancement to use GetFileType() in Windows, since the Windows C runtime does not provide fcntl(). |
Thank you! |
Fixed by #29821 |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: