Skip to content

Commit f7ecfac

Browse files
authored
Doc nits for bpo-16500 (#1841)
* Doc nits for bpo-16500 * Fix more references
1 parent eca7da0 commit f7ecfac

File tree

8 files changed

+25
-13
lines changed

8 files changed

+25
-13
lines changed

Doc/c-api/init.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ Additionally, when extending or embedding Python, calling :c:func:`fork`
564564
directly rather than through :func:`os.fork` (and returning to or calling
565565
into Python) may result in a deadlock by one of Python's internal locks
566566
being held by a thread that is defunct after the fork.
567-
:c:func:`PyOS_AfterFork` tries to reset the necessary locks, but is not
567+
:c:func:`PyOS_AfterFork_Child` tries to reset the necessary locks, but is not
568568
always able to.
569569

570570

@@ -675,9 +675,9 @@ code, or when embedding the Python interpreter:
675675
676676
.. c:function:: void PyEval_ReInitThreads()
677677
678-
This function is called from :c:func:`PyOS_AfterFork` to ensure that newly
679-
created child processes don't hold locks referring to threads which
680-
are not running in the child process.
678+
This function is called from :c:func:`PyOS_AfterFork_Child` to ensure
679+
that newly created child processes don't hold locks referring to threads
680+
which are not running in the child process.
681681
682682
683683
The following functions use thread-local storage, and are not compatible

Doc/whatsnew/3.7.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,10 @@ Serhiy Storchaka in :issue:`28682`.)
166166
Added support for :ref:`file descriptors <path_fd>` in :func:`~os.scandir`
167167
on Unix. (Contributed by Serhiy Storchaka in :issue:`25996`.)
168168

169+
New function :func:`os.register_at_fork` allows registering Python callbacks
170+
to be executed on a process fork. (Contributed by Antoine Pitrou in
171+
:issue:`16500`.)
172+
169173
unittest.mock
170174
-------------
171175

@@ -243,6 +247,11 @@ Build and C API Changes
243247
* Added functions :c:func:`PySlice_Unpack` and :c:func:`PySlice_AdjustIndices`.
244248
(Contributed by Serhiy Storchaka in :issue:`27867`.)
245249

250+
* :c:func:`PyOS_AfterFork` is deprecated in favour of the new functions
251+
:c:func:`PyOS_BeforeFork`, :c:func:`PyOS_AfterFork_Parent` and
252+
:c:func:`PyOS_AfterFork_Child`. (Contributed by Antoine Pitrou in
253+
:issue:`16500`.)
254+
246255

247256
Deprecated
248257
==========

Lib/threading.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,8 +1320,8 @@ def main_thread():
13201320

13211321
def _after_fork():
13221322
# This function is called by Python/ceval.c:PyEval_ReInitThreads which
1323-
# is called from PyOS_AfterFork. Here we cleanup threading module state
1324-
# that should not exist after a fork.
1323+
# is called from PyOS_AfterFork_Child. Here we cleanup threading module
1324+
# state that should not exist after a fork.
13251325

13261326
# Reset _active_limbo_lock, in case we forked while the lock was held
13271327
# by another (non-forked) thread. http://bugs.python.org/issue874900

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,6 +1052,9 @@ Windows
10521052
C API
10531053
-----
10541054

1055+
- bpo-16500: Deprecate PyOS_AfterFork() and add PyOS_BeforeFork(),
1056+
PyOS_AfterFork_Parent() and PyOS_AfterFork_Child().
1057+
10551058
- bpo-6532: The type of results of PyThread_start_new_thread() and
10561059
PyThread_get_thread_ident(), and the id parameter of
10571060
PyThreadState_SetAsyncExc() changed from "long" to "unsigned long".

Python/ceval.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,10 @@ PyEval_ReleaseThread(PyThreadState *tstate)
232232
drop_gil(tstate);
233233
}
234234

235-
/* This function is called from PyOS_AfterFork to destroy all threads which are
236-
* not running in the child process, and clear internal locks which might be
237-
* held by those threads. (This could also be done using pthread_atfork
238-
* mechanism, at least for the pthreads implementation.) */
235+
/* This function is called from PyOS_AfterFork_Child to destroy all threads
236+
* which are not running in the child process, and clear internal locks
237+
* which might be held by those threads.
238+
*/
239239

240240
void
241241
PyEval_ReInitThreads(void)

Python/import.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ _PyImport_ReleaseLock(void)
194194
return 1;
195195
}
196196

197-
/* This function is called from PyOS_AfterFork to ensure that newly
197+
/* This function is called from PyOS_AfterFork_Child to ensure that newly
198198
created child processes do not share locks with the parent.
199199
We now acquire the import lock around fork() calls but on some platforms
200200
(Solaris 9 and earlier? see isue7242) that still left us with problems. */

Python/pystate.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ _PyGILState_Fini(void)
800800
autoInterpreterState = NULL;
801801
}
802802

803-
/* Reset the TLS key - called by PyOS_AfterFork().
803+
/* Reset the TLS key - called by PyOS_AfterFork_Child().
804804
* This should not be necessary, but some - buggy - pthread implementations
805805
* don't reset TLS upon fork(), see issue #10517.
806806
*/

Python/thread.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ PyThread_delete_key_value(int key)
325325
}
326326

327327
/* Forget everything not associated with the current thread id.
328-
* This function is called from PyOS_AfterFork(). It is necessary
328+
* This function is called from PyOS_AfterFork_Child(). It is necessary
329329
* because other thread ids which were in use at the time of the fork
330330
* may be reused for new threads created in the forked process.
331331
*/

0 commit comments

Comments
 (0)