This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: os.dup2(fd, fd, inheritable=False) behaves inconsistently
Type: behavior Stage: patch review
Components: Extension Modules, Library (Lib) Versions: Python 3.10, Python 3.9, Python 3.8
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, eryksun, izbyshev
Priority: normal Keywords: patch

Created on 2018-02-17 03:24 by izbyshev, last changed 2022-04-11 14:58 by admin.

Pull Requests
URL Status Linked Edit
PR 5713 open izbyshev, 2018-02-17 03:28
Messages (3)
msg312266 - (view) Author: Alexey Izbyshev (izbyshev) * (Python triager) Date: 2018-02-17 03:24
os.dup2(fd, fd, inheritable=False) may fail or change fd inheritability in following ways:

1) POSIX without F_DUP2FD_CLOEXEC
1.1) dup3() is available (a common case for Linux): OSError (EINVAL, dup3() doesn't allow equal descriptors)
1.2) dup3() is not available: fd made non-inheritable

2) POSIX with F_DUP2FD_CLOEXEC (FreeBSD): inheritability is not changed

3) Windows: fd made non-inheritable

In contrast, os.dup2(fd, fd, inheritable=True) never changes fd inheritability (same as before PEP 446 landed). I suggest to make os.dup2(fd, fd, inheritable=False) behave the same.
msg312295 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2018-02-18 02:26
In Windows the CRT file descriptor is actually still inheritable. This only makes the underlying OS handle non-inheritable. I don't think there's a way to make an existing FD non-inheritable using public CRT functions. See issue 32865.
msg312298 - (view) Author: Alexey Izbyshev (izbyshev) * (Python triager) Date: 2018-02-18 04:36
@eryksun: Thank you for the note! I've commented on #32865. This adds even more inconsistency to this corner case.
History
Date User Action Args
2022-04-11 14:58:57adminsetgithub: 77043
2021-03-20 14:32:55vstinnersetnosy: - vstinner
2021-03-20 06:38:25eryksunsetversions: + Python 3.8, Python 3.9, Python 3.10, - Python 3.6, Python 3.7
2018-02-18 04:36:34izbyshevsetmessages: + msg312298
2018-02-18 02:26:17eryksunsetnosy: + eryksun
messages: + msg312295
2018-02-17 03:28:12izbyshevsetkeywords: + patch
stage: patch review
pull_requests: + pull_request5503
2018-02-17 03:24:02izbyshevcreate