Skip to content

Commit 9b62a4e

Browse files
ronaldoussorenwillingc
authored andcommitted
pythongh-105912: document gotcha with using os.fork on macOS (python#112871)
* 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. Co-authored-by: Carol Willing <[email protected]>
1 parent 62fbe10 commit 9b62a4e

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
@@ -4383,6 +4383,11 @@ written in Python, such as a mail server's external command delivery program.
43834383
If you use TLS sockets in an application calling ``fork()``, see
43844384
the warning in the :mod:`ssl` documentation.
43854385

4386+
.. warning::
4387+
4388+
On macOS the use of this function is unsafe when mixed with using
4389+
higher-level system APIs, and that includes using :mod:`urllib.request`.
4390+
43864391
.. versionchanged:: 3.8
43874392
Calling ``fork()`` in a subinterpreter is no longer supported
43884393
(:exc:`RuntimeError` is raised).
@@ -4422,6 +4427,11 @@ written in Python, such as a mail server's external command delivery program.
44224427

44234428
.. audit-event:: os.forkpty "" os.forkpty
44244429

4430+
.. warning::
4431+
4432+
On macOS the use of this function is unsafe when mixed with using
4433+
higher-level system APIs, and that includes using :mod:`urllib.request`.
4434+
44254435
.. versionchanged:: 3.12
44264436
If Python is able to detect that your process has multiple
44274437
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 environment 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)