:c:func:`Py_Initialize` is called again.
+.. c:function:: int Py_IsFinalizing()
+
+ Return true (non-zero) if the main Python interpreter is
+ :term:`shutting down <interpreter shutdown>`. Return false (zero) otherwise.
+
+ .. versionadded:: 3.13
+
+
.. c:function:: int Py_FinalizeEx()
Undo all initializations made by :c:func:`Py_Initialize` and subsequent use of
.. note::
Calling this function from a thread when the runtime is finalizing
will terminate the thread, even if the thread was not created by Python.
- You can use :c:func:`!_Py_IsFinalizing` or :func:`sys.is_finalizing` to
+ You can use :c:func:`Py_IsFinalizing` or :func:`sys.is_finalizing` to
check if the interpreter is in process of being finalized before calling
this function to avoid unwanted termination.
.. note::
Calling this function from a thread when the runtime is finalizing
will terminate the thread, even if the thread was not created by Python.
- You can use :c:func:`!_Py_IsFinalizing` or :func:`sys.is_finalizing` to
+ You can use :c:func:`Py_IsFinalizing` or :func:`sys.is_finalizing` to
check if the interpreter is in process of being finalized before calling
this function to avoid unwanted termination.
.. note::
Calling this function from a thread when the runtime is finalizing
will terminate the thread, even if the thread was not created by Python.
- You can use :c:func:`!_Py_IsFinalizing` or :func:`sys.is_finalizing` to
+ You can use :c:func:`Py_IsFinalizing` or :func:`sys.is_finalizing` to
check if the interpreter is in process of being finalized before calling
this function to avoid unwanted termination.
.. function:: is_finalizing()
- Return :const:`True` if the Python interpreter is
- :term:`shutting down <interpreter shutdown>`, :const:`False` otherwise.
+ Return :const:`True` if the main Python interpreter is
+ :term:`shutting down <interpreter shutdown>`. Return :const:`False` otherwise.
.. versionadded:: 3.5
not needed.
(Contributed by Victor Stinner in :gh:`106004`.)
+* Add :c:func:`Py_IsFinalizing` function: check if the main Python interpreter is
+ :term:`shutting down <interpreter shutdown>`.
+ (Contributed by Victor Stinner in :gh:`108014`.)
+
Porting to Python 3.13
----------------------
typedef void (*atexit_datacallbackfunc)(void *);
PyAPI_FUNC(int) PyUnstable_AtExit(
PyInterpreterState *, atexit_datacallbackfunc, void *);
+
+PyAPI_FUNC(int) Py_IsFinalizing(void);
extern const char* _Py_gitidentifier(void);
extern const char* _Py_gitversion(void);
-extern int _Py_IsFinalizing(void);
PyAPI_FUNC(int) _Py_IsInterpreterFinalizing(PyInterpreterState *interp);
/* Random */
--- /dev/null
+Add :c:func:`Py_IsFinalizing` function: check if the main Python interpreter is
+:term:`shutting down <interpreter shutdown>`. Patch by Victor Stinner.
}
if (is_true && !_Py_IsInterpreterFinalizing(_PyInterpreterState_GET())) {
/* Only try to capture the traceback if the interpreter is not being
- finalized. The original motivation to add a `_Py_IsFinalizing()`
+ finalized. The original motivation to add a `Py_IsFinalizing()`
call was to prevent SIGSEGV when a Future is created in a __del__
method, which is called during the interpreter shutdown and the
traceback module is already unloaded.
}
int
-_Py_IsFinalizing(void)
+Py_IsFinalizing(void)
{
return _PyRuntimeState_GetFinalizing(&_PyRuntime) != NULL;
}
sys_is_finalizing_impl(PyObject *module)
/*[clinic end generated code: output=735b5ff7962ab281 input=f0df747a039948a5]*/
{
- return PyBool_FromLong(_Py_IsFinalizing());
+ return PyBool_FromLong(Py_IsFinalizing());
}
#ifdef Py_STATS