@@ -4157,15 +4157,38 @@ written in Python, such as a mail server's external command delivery program.
4157
4157
4158
4158
.. audit-event :: os.fork "" os.fork
4159
4159
4160
+ .. warning ::
4161
+
4162
+ If you use TLS sockets in an application calling ``fork() ``, see
4163
+ the warning in the :mod: `ssl ` documentation.
4164
+
4160
4165
.. versionchanged :: 3.8
4161
4166
Calling ``fork() `` in a subinterpreter is no longer supported
4162
4167
(:exc: `RuntimeError ` is raised).
4163
4168
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.
4167
4190
4168
- .. availability :: Unix , not Emscripten, not WASI.
4191
+ .. availability :: POSIX , not Emscripten, not WASI.
4169
4192
4170
4193
4171
4194
.. function :: forkpty()
@@ -4178,6 +4201,11 @@ written in Python, such as a mail server's external command delivery program.
4178
4201
4179
4202
.. audit-event :: os.forkpty "" os.forkpty
4180
4203
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
+
4181
4209
.. versionchanged :: 3.8
4182
4210
Calling ``forkpty() `` in a subinterpreter is no longer supported
4183
4211
(:exc: `RuntimeError ` is raised).
0 commit comments