Skip to content

Commit 03fa2df

Browse files
gh-120838: Add a Note in the Docs About Expectations for Py_Finalize() (gh-120839)
1 parent 4628320 commit 03fa2df

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
@@ -396,9 +396,16 @@ Initializing and finalizing the interpreter
396396
:c:func:`Py_NewInterpreter` below) that were created and not yet destroyed since
397397
the last call to :c:func:`Py_Initialize`. Ideally, this frees all memory
398398
allocated by the Python interpreter. This is a no-op when called for a second
399-
time (without calling :c:func:`Py_Initialize` again first). Normally the
400-
return value is ``0``. If there were errors during finalization
401-
(flushing buffered data), ``-1`` is returned.
399+
time (without calling :c:func:`Py_Initialize` again first).
400+
401+
Since this is the reverse of :c:func:`Py_Initialize`, it should be called
402+
in the same thread with the same interpreter active. That means
403+
the main thread and the main interpreter.
404+
This should never be called while :c:func:`Py_RunMain` is running.
405+
406+
Normally the return value is ``0``.
407+
If there were errors during finalization (flushing buffered data),
408+
``-1`` is returned.
402409
403410
This function is provided for a number of reasons. An embedding application
404411
might want to restart Python without having to restart the application itself.

0 commit comments

Comments
 (0)