@@ -25,7 +25,7 @@ Initializing and finalizing the interpreter
25
25
triple: module; search; path
26
26
single: PySys_SetArgv()
27
27
single: PySys_SetArgvEx()
28
- single: Py_Finalize ()
28
+ single: Py_FinalizeEx ()
29
29
30
30
Initialize the Python interpreter. In an application embedding Python, this
31
31
should be called before using any other Python/C API functions; with the
@@ -34,7 +34,7 @@ Initializing and finalizing the interpreter
34
34
modules :mod: `builtins `, :mod: `__main__ ` and :mod: `sys `. It also initializes
35
35
the module search path (``sys.path ``). It does not set ``sys.argv ``; use
36
36
:c:func: `PySys_SetArgvEx ` for that. This is a no-op when called for a second time
37
- (without calling :c:func: `Py_Finalize ` first). There is no return value; it is a
37
+ (without calling :c:func: `Py_FinalizeEx ` first). There is no return value; it is a
38
38
fatal error if the initialization fails.
39
39
40
40
@@ -48,19 +48,20 @@ Initializing and finalizing the interpreter
48
48
.. c:function:: int Py_IsInitialized()
49
49
50
50
Return true (nonzero) when the Python interpreter has been initialized, false
51
- (zero) if not. After :c:func:`Py_Finalize ` is called, this returns false until
51
+ (zero) if not. After :c:func:`Py_FinalizeEx ` is called, this returns false until
52
52
:c:func:`Py_Initialize` is called again.
53
53
54
54
55
- .. c:function:: void Py_Finalize ()
55
+ .. c:function:: int Py_FinalizeEx ()
56
56
57
57
Undo all initializations made by :c:func:`Py_Initialize` and subsequent use of
58
58
Python/C API functions, and destroy all sub-interpreters (see
59
59
:c:func: `Py_NewInterpreter ` below) that were created and not yet destroyed since
60
60
the last call to :c:func:`Py_Initialize`. Ideally, this frees all memory
61
61
allocated by the Python interpreter. This is a no-op when called for a second
62
- time (without calling :c:func: `Py_Initialize ` again first). There is no return
63
- value; errors during finalization are ignored.
62
+ time (without calling :c:func: `Py_Initialize ` again first). Normally the
63
+ return value is 0. If there were errors during finalization
64
+ (flushing buffered data), -1 is returned.
64
65
65
66
This function is provided for a number of reasons. An embedding application
66
67
might want to restart Python without having to restart the application itself.
@@ -79,7 +80,15 @@ Initializing and finalizing the interpreter
79
80
freed. Some memory allocated by extension modules may not be freed. Some
80
81
extensions may not work properly if their initialization routine is called more
81
82
than once; this can happen if an application calls :c:func:`Py_Initialize` and
82
- :c:func: `Py_Finalize ` more than once.
83
+ :c:func: `Py_FinalizeEx ` more than once.
84
+
85
+ .. versionadded :: 3.6
86
+
87
+
88
+ .. c :function :: void Py_Finalize ()
89
+
90
+ This is a backwards-compatible version of :c:func:`Py_FinalizeEx` that
91
+ disregards the return value.
83
92
84
93
85
94
Process-wide parameters
@@ -107,7 +116,7 @@ Process-wide parameters
107
116
Note that :data:`sys.stderr` always uses the "backslashreplace" error
108
117
handler, regardless of this (or any other) setting.
109
118
110
- If :c:func:`Py_Finalize ` is called, this function will need to be called
119
+ If :c:func:`Py_FinalizeEx ` is called, this function will need to be called
111
120
again in order to affect subsequent calls to :c:func:`Py_Initialize`.
112
121
113
122
Returns 0 if successful, a nonzero value on error (e.g. calling after the
@@ -918,7 +927,7 @@ using the following functions:
918
927
entry.)
919
928
920
929
.. index::
921
- single: Py_Finalize ()
930
+ single: Py_FinalizeEx ()
922
931
single: Py_Initialize()
923
932
924
933
Extension modules are shared between (sub-)interpreters as follows: the first
@@ -928,22 +937,22 @@ using the following functions:
928
937
and filled with the contents of this copy; the extension' s ``init`` function is
929
938
not called. Note that this is different from what happens when an extension is
930
939
imported after the interpreter has been completely re-initialized by calling
931
- :c:func:`Py_Finalize ` and :c:func:`Py_Initialize`; in that case, the extension' s
940
+ :c:func:`Py_FinalizeEx ` and :c:func:`Py_Initialize`; in that case, the extension' s
932
941
``initmodule `` function *is * called again.
933
942
934
943
.. index :: single: close() (in module os)
935
944
936
945
937
946
.. c :function :: void Py_EndInterpreter (PyThreadState *tstate)
938
947
939
- .. index :: single: Py_Finalize ()
948
+ .. index :: single: Py_FinalizeEx ()
940
949
941
950
Destroy the (sub-)interpreter represented by the given thread state. The given
942
951
thread state must be the current thread state. See the discussion of thread
943
952
states below. When the call returns, the current thread state is *NULL*. All
944
953
thread states associated with this interpreter are destroyed. (The global
945
954
interpreter lock must be held before calling this function and is still held
946
- when it returns.) :c:func:`Py_Finalize ` will destroy all sub-interpreters that
955
+ when it returns.) :c:func:`Py_FinalizeEx ` will destroy all sub-interpreters that
947
956
haven't been explicitly destroyed at that point.
948
957
949
958
0 commit comments