Skip to content

Commit 22a99ca

Browse files
miss-islingtonraixyzadityavstinner
authored
[3.14] gh-142302: Fix mkstemp() documentation: clarify file descriptor inheritance behavior (GH-142338) (#143486)
gh-142302: Fix mkstemp() documentation: clarify file descriptor inheritance behavior (GH-142338) The documentation incorrectly stated that the file descriptor is not inherited by child processes. In reality, the close-on-exec flag (when available) only prevents inheritance across exec() calls, not fork(). (cherry picked from commit e79c9b7) Co-authored-by: ADITYA RAI <adi.hack1234@gmail.com> Co-authored-by: Victor Stinner <vstinner@python.org>
1 parent b9b2b3d commit 22a99ca

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

Doc/library/os.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1961,7 +1961,8 @@ can be inherited by child processes. Since Python 3.4, file descriptors
19611961
created by Python are non-inheritable by default.
19621962

19631963
On UNIX, non-inheritable file descriptors are closed in child processes at the
1964-
execution of a new program, other file descriptors are inherited.
1964+
execution of a new program, other file descriptors are inherited. Note that
1965+
non-inheritable file descriptors are still *inherited* by child processes on :func:`os.fork`.
19651966

19661967
On Windows, non-inheritable handles and file descriptors are closed in child
19671968
processes, except for standard streams (file descriptors 0, 1 and 2: stdin, stdout

Doc/library/tempfile.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,9 @@ The module defines the following user-callable items:
225225
properly implements the :const:`os.O_EXCL` flag for :func:`os.open`. The
226226
file is readable and writable only by the creating user ID. If the
227227
platform uses permission bits to indicate whether a file is executable,
228-
the file is executable by no one. The file descriptor is not inherited
229-
by child processes.
228+
the file is executable by no one.
229+
230+
The file descriptor is :ref:`not inherited by child processes <fd_inheritance>`.
230231

231232
Unlike :func:`TemporaryFile`, the user of :func:`mkstemp` is responsible
232233
for deleting the temporary file when done with it.

0 commit comments

Comments
 (0)