[issue45915] Use fcntl(fd, F_GETFD) to check whether an fd is valid

2021-12-13 Thread Eryk Sun
Eryk Sun added the comment: PR 29821 adds __APPLE__ to the platforms that use fcntl(fd, F_GETFD). Is this okay on macOS, given bpo-30225? Apparently fstat() fails if the other end of a pipe is closed. -- ___ Python tracker

[issue45915] Use fcntl(fd, F_GETFD) to check whether an fd is valid

2021-12-13 Thread Dong-hee Na
Change by Dong-hee Na : -- nosy: +corona10 nosy_count: 3.0 -> 4.0 pull_requests: +28311 pull_request: https://github.com/python/cpython/pull/30082 ___ Python tracker ___ __

[issue45915] Use fcntl(fd, F_GETFD) to check whether an fd is valid

2021-11-28 Thread Christian Heimes
Christian Heimes added the comment: Thank you! -- ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://ma

[issue45915] Use fcntl(fd, F_GETFD) to check whether an fd is valid

2021-11-28 Thread Eryk Sun
Eryk Sun added the comment: I've created bpo-45919 with a suggested enhancement to use GetFileType() in Windows, since the Windows C runtime does not provide fcntl(). -- ___ Python tracker _

[issue45915] Use fcntl(fd, F_GETFD) to check whether an fd is valid

2021-11-28 Thread Eryk Sun
Change by Eryk Sun : -- Removed message: https://bugs.python.org/msg407216 ___ Python tracker ___ ___ Python-bugs-list mailing list

[issue45915] Use fcntl(fd, F_GETFD) to check whether an fd is valid

2021-11-28 Thread Christian Heimes
Christian Heimes added the comment: New changeset f87ea0350286837e9e96de03f8bfa215176c2928 by Christian Heimes in branch 'main': bpo-45915: use fcntl(fd, F_GETFD) in is_valid_fd() (GH-29821) https://github.com/python/cpython/commit/f87ea0350286837e9e96de03f8bfa215176c2928 -- __

[issue45915] Use fcntl(fd, F_GETFD) to check whether an fd is valid

2021-11-28 Thread Eryk Sun
Eryk Sun added the comment: In Windows, GetFileType((HANDLE)_get_osfhandle(fd)) is several times faster than close(dup(fd)). For example: #if defined(MS_WINDOWS) int type; _Py_BEGIN_SUPPRESS_IPH type = GetFileType((HANDLE)_get_osfhandle(fd)); _Py_END_SUPPRESS_IPH return ty

[issue45915] Use fcntl(fd, F_GETFD) to check whether an fd is valid

2021-11-28 Thread Christian Heimes
Change by Christian Heimes : -- keywords: +patch pull_requests: +28053 stage: -> patch review pull_request: https://github.com/python/cpython/pull/29821 ___ Python tracker ___

[issue45915] Use fcntl(fd, F_GETFD) to check whether an fd is valid

2021-11-28 Thread Christian Heimes
New submission from Christian Heimes : 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 th