Skip to content

Commit a57d917

Browse files
[3.12] gh-120838: Add a Note in the Docs About Expectations for Py_Finalize() (gh-120853)
(cherry picked from commit 03fa2df, AKA gh-120839) Co-authored-by: Eric Snow <[email protected]>
1 parent 9bbb91c commit a57d917

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

Doc/c-api/init.rst

+10-3
Original file line numberDiff line numberDiff line change
@@ -388,9 +388,16 @@ Initializing and finalizing the interpreter
388388
:c:func:`Py_NewInterpreter` below) that were created and not yet destroyed since
389389
the last call to :c:func:`Py_Initialize`. Ideally, this frees all memory
390390
allocated by the Python interpreter. This is a no-op when called for a second
391-
time (without calling :c:func:`Py_Initialize` again first). Normally the
392-
return value is ``0``. If there were errors during finalization
393-
(flushing buffered data), ``-1`` is returned.
391+
time (without calling :c:func:`Py_Initialize` again first).
392+
393+
Since this is the reverse of :c:func:`Py_Initialize`, it should be called
394+
in the same thread with the same interpreter active. That means
395+
the main thread and the main interpreter.
396+
This should never be called while :c:func:`Py_RunMain` is running.
397+
398+
Normally the return value is ``0``.
399+
If there were errors during finalization (flushing buffered data),
400+
``-1`` is returned.
394401
395402
This function is provided for a number of reasons. An embedding application
396403
might want to restart Python without having to restart the application itself.

0 commit comments

Comments
 (0)