Skip to content

Commit 9df2d1b

Browse files
pythongh-105912: document gotcha with using os.fork on macOS
Using ``fork(2)`` on macOS when also using higher-level system APIs in the parent proces can crash on macOS because those system APIs are not written to handle this usage pattern. There's nothing we can do about this other than documenting the problem.
1 parent 2d76be2 commit 9df2d1b

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

Doc/library/os.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4373,6 +4373,11 @@ written in Python, such as a mail server's external command delivery program.
43734373
If you use TLS sockets in an application calling ``fork()``, see
43744374
the warning in the :mod:`ssl` documentation.
43754375

4376+
.. warning::
4377+
4378+
On macOS the use of this function is unsafe when mixed with using
4379+
higher-level system APIs, and that includes using :mod:`urllib.request`.
4380+
43764381
.. versionchanged:: 3.8
43774382
Calling ``fork()`` in a subinterpreter is no longer supported
43784383
(:exc:`RuntimeError` is raised).
@@ -4412,6 +4417,11 @@ written in Python, such as a mail server's external command delivery program.
44124417

44134418
.. audit-event:: os.forkpty "" os.forkpty
44144419

4420+
.. warning::
4421+
4422+
On macOS the use of this function is unsafe when mixed with using
4423+
higher-level system APIs, and that includes using :mod:`urllib.request`.
4424+
44154425
.. versionchanged:: 3.12
44164426
If Python is able to detect that your process has multiple
44174427
threads, this now raises a :exc:`DeprecationWarning`. See the

Doc/library/pty.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ The :mod:`pty` module defines the following functions:
3333
file descriptor connected to the child's controlling terminal (and also to the
3434
child's standard input and output).
3535

36+
.. warning:: On macOS the use of this function is unsafe when mixed with using
37+
higher-level system APIs, and that includes using :mod:`urllib.request`.
38+
3639

3740
.. function:: openpty()
3841

Doc/library/urllib.request.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ authentication, redirections, cookies and more.
2121
The `Requests package <https://requests.readthedocs.io/en/master/>`_
2222
is recommended for a higher-level HTTP client interface.
2323

24+
.. warning::
25+
26+
On macOS it is unsafe to use this module in programs using
27+
:func:`os.fork` because the :func:`getproxies` implementation for
28+
macOS uses a higher-level system API. Set the environement variable
29+
``no_proxy`` to ``*`` to avoid this problem
30+
(e.g. ``os.environ["no_proxy"] = "*"``).
31+
2432
.. include:: ../includes/wasm-notavail.rst
2533

2634
The :mod:`urllib.request` module defines the following functions:

0 commit comments

Comments
 (0)