Skip to content

Commit 6f439ee

Browse files
gh-141004: Document Py_FrozenMain (#159724)
1 parent c38d75c commit 6f439ee

2 files changed

Lines changed: 42 additions & 2 deletions

File tree

‎Doc/c-api/interp-lifecycle.rst‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,48 @@ Initializing and finalizing the interpreter
265265
first initialized).
266266
267267
268+
.. c:function:: int Py_FrozenMain(int argc, char **argv)
269+
270+
.. index:: single: freeze utility
271+
272+
The main program for a "frozen" Python program (an executable that embeds
273+
the interpreter together with the bytecode of the program's modules, as
274+
produced by the :program:`freeze` utility; see :source:`Tools/freeze`).
275+
276+
This function initializes the interpreter, imports the frozen module named
277+
``__main__``, and finalizes the interpreter.
278+
The frozen modules must have been registered in
279+
:c:var:`PyImport_FrozenModules` before calling this function;
280+
it is a fatal error if ``__main__`` is not among them.
281+
282+
*argc* and *argv* are byte strings like the arguments of a C program's
283+
``main`` function, and are passed to the interpreter with
284+
:c:func:`PyConfig_SetBytesArgv`.
285+
Unlike :c:func:`Py_Main`, the arguments are not parsed as Python command
286+
line options (:c:member:`PyConfig.parse_argv` is ``0``), so all of them
287+
are made available to the program in :data:`sys.argv`.
288+
Apart from that, the interpreter uses the
289+
:ref:`Python Configuration <init-python-config>`, so environment variables
290+
such as :envvar:`PYTHONPATH` are honored.
291+
Warnings about the path configuration
292+
(:c:member:`PyConfig.pathconfig_warnings`) are suppressed.
293+
If :envvar:`PYTHONINSPECT` is set and standard input is a terminal, an
294+
interactive prompt is run after ``__main__`` has finished, as with the
295+
:option:`-i` option.
296+
297+
Return ``0`` if ``__main__`` ran without an unhandled exception, ``1``
298+
otherwise, and ``120`` if finalizing the interpreter failed (see
299+
:c:func:`Py_FinalizeEx`).
300+
An unhandled :exc:`SystemExit` terminates the process.
301+
If the interpreter cannot be initialized, the process exits via
302+
:c:func:`Py_ExitStatusException`.
303+
304+
On Windows, this function is not exported by the Python DLL.
305+
The :program:`freeze` utility compiles :file:`Python/frozenmain.c` into the
306+
frozen program instead, together with the Windows-specific hooks that the
307+
function requires.
308+
309+
268310
.. c:function:: int Py_RunMain(void)
269311
270312
Executes the main module in a fully configured CPython runtime.

‎Tools/check-c-api-docs/ignored_c_api.txt‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ PyCFunction_GET_CLASS
3232
PyDescr_NAME
3333
PyDescr_TYPE
3434
PyWrapperFlag_KEYWORDS
35-
# cpython/pylifecycle.h
36-
Py_FrozenMain
3735
# cpython/objimpl.h
3836
PyObject_GET_WEAKREFS_LISTPTR
3937
# cpython/pythonrun.h

0 commit comments

Comments
 (0)