diff --git a/Doc/library/os.rst b/Doc/library/os.rst index 671270d6112212..2c0e56de55383e 100644 --- a/Doc/library/os.rst +++ b/Doc/library/os.rst @@ -1969,7 +1969,11 @@ can be inherited by child processes. Since Python 3.4, file descriptors created by Python are non-inheritable by default. On UNIX, non-inheritable file descriptors are closed in child processes at the -execution of a new program, other file descriptors are inherited. +execution of a new program (via :func:`os.execl` and related functions), but +they remain accessible after :func:`os.fork` until an exec call occurs. In other +words, a forked child process can still use the file descriptor, but it will be +closed if that child process calls exec to run a new program. Inheritable file +descriptors are inherited across both fork and exec calls. On Windows, non-inheritable handles and file descriptors are closed in child processes, except for standard streams (file descriptors 0, 1 and 2: stdin, stdout diff --git a/Doc/library/tempfile.rst b/Doc/library/tempfile.rst index f0a81a093b435b..88dfc4ca3aed78 100644 --- a/Doc/library/tempfile.rst +++ b/Doc/library/tempfile.rst @@ -225,8 +225,12 @@ The module defines the following user-callable items: properly implements the :const:`os.O_EXCL` flag for :func:`os.open`. The file is readable and writable only by the creating user ID. If the platform uses permission bits to indicate whether a file is executable, - the file is executable by no one. The file descriptor is not inherited - by child processes. + the file is executable by no one. + + The file descriptor is not inherited by child processes across + :func:`exec ` calls, but will be inherited by child + processes created via :func:`os.fork`. See :ref:`fd_inheritance` + for more information. Unlike :func:`TemporaryFile`, the user of :func:`mkstemp` is responsible for deleting the temporary file when done with it.