gh-108014: Add Py_IsFinalizing() function (#108032) · python/cpython@3ff5ef2 · GitHub
Skip to content

Commit 3ff5ef2

Browse files
gh-108014: Add Py_IsFinalizing() function (#108032)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
1 parent cc58ec9 commit 3ff5ef2

9 files changed

Lines changed: 24 additions & 9 deletions

File tree

Doc/c-api/init.rst

Lines changed: 11 additions & 3 deletions

Doc/library/sys.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,8 +1121,8 @@ always available.
11211121

11221122
.. function:: is_finalizing()
11231123

1124-
Return :const:`True` if the Python interpreter is
1125-
:term:`shutting down <interpreter shutdown>`, :const:`False` otherwise.
1124+
Return :const:`True` if the main Python interpreter is
1125+
:term:`shutting down <interpreter shutdown>`. Return :const:`False` otherwise.
11261126

11271127
.. versionadded:: 3.5
11281128

Doc/whatsnew/3.13.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,10 @@ New Features
832832
not needed.
833833
(Contributed by Victor Stinner in :gh:`106004`.)
834834

835+
* Add :c:func:`Py_IsFinalizing` function: check if the main Python interpreter is
836+
:term:`shutting down <interpreter shutdown>`.
837+
(Contributed by Victor Stinner in :gh:`108014`.)
838+
835839
Porting to Python 3.13
836840
----------------------
837841

Include/cpython/pylifecycle.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,5 @@ PyAPI_FUNC(PyStatus) Py_NewInterpreterFromConfig(
8181
typedef void (*atexit_datacallbackfunc)(void *);
8282
PyAPI_FUNC(int) PyUnstable_AtExit(
8383
PyInterpreterState *, atexit_datacallbackfunc, void *);
84+
85+
PyAPI_FUNC(int) Py_IsFinalizing(void);

Include/internal/pycore_pylifecycle.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ extern int _Py_FdIsInteractive(FILE *fp, PyObject *filename);
9898
extern const char* _Py_gitidentifier(void);
9999
extern const char* _Py_gitversion(void);
100100

101-
extern int _Py_IsFinalizing(void);
102101
PyAPI_FUNC(int) _Py_IsInterpreterFinalizing(PyInterpreterState *interp);
103102

104103
/* Random */
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Add :c:func:`Py_IsFinalizing` function: check if the main Python interpreter is
2+
:term:`shutting down <interpreter shutdown>`. Patch by Victor Stinner.

Modules/_asynciomodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ future_init(FutureObj *fut, PyObject *loop)
529529
}
530530
if (is_true && !_Py_IsInterpreterFinalizing(_PyInterpreterState_GET())) {
531531
/* Only try to capture the traceback if the interpreter is not being
532-
finalized. The original motivation to add a `_Py_IsFinalizing()`
532+
finalized. The original motivation to add a `Py_IsFinalizing()`
533533
call was to prevent SIGSEGV when a Future is created in a __del__
534534
method, which is called during the interpreter shutdown and the
535535
traceback module is already unloaded.

Python/pylifecycle.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ _PyRuntime_Finalize(void)
129129
}
130130

131131
int
132-
_Py_IsFinalizing(void)
132+
Py_IsFinalizing(void)
133133
{
134134
return _PyRuntimeState_GetFinalizing(&_PyRuntime) != NULL;
135135
}

Python/sysmodule.c

Lines changed: 1 addition & 1 deletion

0 commit comments

Comments
 (0)