diff options
author | chgnrdv <52372310+chgnrdv@users.noreply.github.com> | 2023-06-04 04:06:45 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-04 04:06:45 (GMT) |
commit | ce558e69d4087dd3653207de78345fbb8a2c7835 (patch) | |
tree | a96a5b705ac12fced6d95ca55787d270550edbf8 /Doc/library/atexit.rst | |
parent | eaff9c39aa1a70d401521847cc35bec883ae9772 (diff) | |
download | cpython-ce558e69d4087dd3653207de78345fbb8a2c7835.zip cpython-ce558e69d4087dd3653207de78345fbb8a2c7835.tar.gz cpython-ce558e69d4087dd3653207de78345fbb8a2c7835.tar.bz2 |
gh-104690 Disallow thread creation and fork at interpreter finalization (#104826)
Disallow thread creation and fork at interpreter finalization.
in the following functions, check if interpreter is finalizing and raise `RuntimeError` with appropriate message:
* `_thread.start_new_thread` and thus `threading`
* `posix.fork`
* `posix.fork1`
* `posix.forkpty`
* `_posixsubprocess.fork_exec` when a `preexec_fn=` is supplied.
---------
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
Diffstat (limited to 'Doc/library/atexit.rst')
-rw-r--r-- | Doc/library/atexit.rst | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/Doc/library/atexit.rst b/Doc/library/atexit.rst index a2bd85b..3dbef69 100644 --- a/Doc/library/atexit.rst +++ b/Doc/library/atexit.rst @@ -48,6 +48,16 @@ a cleanup function is undefined. This function returns *func*, which makes it possible to use it as a decorator. + .. warning:: + Starting new threads or calling :func:`os.fork` from a registered + function can lead to race condition between the main Python + runtime thread freeing thread states while internal :mod:`threading` + routines or the new process try to use that state. This can lead to + crashes rather than clean shutdown. + + .. versionchanged:: 3.12 + Attempts to start a new thread or :func:`os.fork` a new process + in a registered function now leads to :exc:`RuntimeError`. .. function:: unregister(func) |