diff options
author | Carl Meyer <carl@oddbird.net> | 2023-03-08 00:10:58 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-08 00:10:58 (GMT) |
commit | 1e703a473343ed198c9a06a876b25d7d69d4bbd0 (patch) | |
tree | 0ca3e31d0953a8ec475a159e19b5570e104eeefa /Doc/c-api/function.rst | |
parent | a33ca2ad1fcf857817cba505a788e15cf9d6ed0c (diff) | |
download | cpython-1e703a473343ed198c9a06a876b25d7d69d4bbd0.zip cpython-1e703a473343ed198c9a06a876b25d7d69d4bbd0.tar.gz cpython-1e703a473343ed198c9a06a876b25d7d69d4bbd0.tar.bz2 |
gh-102381: don't call watcher callback with dead object (#102382)
Co-authored-by: T. Wouters <thomas@python.org>
Diffstat (limited to 'Doc/c-api/function.rst')
-rw-r--r-- | Doc/c-api/function.rst | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/Doc/c-api/function.rst b/Doc/c-api/function.rst index bc7569d..947ed70 100644 --- a/Doc/c-api/function.rst +++ b/Doc/c-api/function.rst @@ -173,8 +173,19 @@ There are a few functions specific to Python functions. runtime behavior depending on optimization decisions, it does not change the semantics of the Python code being executed. - If the callback returns with an exception set, it must return ``-1``; this - exception will be printed as an unraisable exception using - :c:func:`PyErr_WriteUnraisable`. Otherwise it should return ``0``. + If *event* is ``PyFunction_EVENT_DESTROY``, Taking a reference in the + callback to the about-to-be-destroyed function will resurrect it, preventing + it from being freed at this time. When the resurrected object is destroyed + later, any watcher callbacks active at that time will be called again. + + If the callback sets an exception, it must return ``-1``; this exception will + be printed as an unraisable exception using :c:func:`PyErr_WriteUnraisable`. + Otherwise it should return ``0``. + + There may already be a pending exception set on entry to the callback. In + this case, the callback should return ``0`` with the same exception still + set. This means the callback may not call any other API that can set an + exception unless it saves and clears the exception state first, and restores + it before returning. .. versionadded:: 3.12 |