@@ -4157,15 +4157,38 @@ written in Python, such as a mail server's external command delivery program.
41574157
41584158 .. audit-event :: os.fork "" os.fork
41594159
4160+ .. warning ::
4161+
4162+ If you use TLS sockets in an application calling ``fork() ``, see
4163+ the warning in the :mod: `ssl ` documentation.
4164+
41604165 .. versionchanged :: 3.8
41614166 Calling ``fork() `` in a subinterpreter is no longer supported
41624167 (:exc: `RuntimeError ` is raised).
41634168
4164- .. warning ::
4165-
4166- See :mod: `ssl ` for applications that use the SSL module with fork().
4169+ .. versionchanged :: 3.12
4170+ If Python is able to detect that your process has multiple
4171+ threads, :func: `os.fork ` now raises a :exc: `DeprecationWarning `.
4172+
4173+ We chose to surface this as a warning, when detectable, to better
4174+ inform developers of a design problem that the POSIX platform
4175+ specifically notes as not supported. Even in code that
4176+ *appears * to work, it has never been safe to mix threading with
4177+ :func: `os.fork ` on POSIX platforms. The CPython runtime itself has
4178+ always made API calls that are not safe for use in the child
4179+ process when threads existed in the parent (such as ``malloc `` and
4180+ ``free ``).
4181+
4182+ Users of macOS or users of libc or malloc implementations other
4183+ than those typically found in glibc to date are among those
4184+ already more likely to experience deadlocks running such code.
4185+
4186+ See `this discussion on fork being incompatible with threads
4187+ <https://discuss.python.org/t/33555> `_
4188+ for technical details of why we're surfacing this longstanding
4189+ platform compatibility problem to developers.
41674190
4168- .. availability :: Unix , not Emscripten, not WASI.
4191+ .. availability :: POSIX , not Emscripten, not WASI.
41694192
41704193
41714194.. function :: forkpty()
@@ -4178,6 +4201,11 @@ written in Python, such as a mail server's external command delivery program.
41784201
41794202 .. audit-event :: os.forkpty "" os.forkpty
41804203
4204+ .. versionchanged :: 3.12
4205+ If Python is able to detect that your process has multiple
4206+ threads, this now raises a :exc: `DeprecationWarning `. See the
4207+ longer explanation on :func: `os.fork `.
4208+
41814209 .. versionchanged :: 3.8
41824210 Calling ``forkpty() `` in a subinterpreter is no longer supported
41834211 (:exc: `RuntimeError ` is raised).
0 commit comments