Skip to content

Commit cb6a4bb

Browse files
[3.14] gh-141004: Document Py_FrozenMain (GH-159724) (GH-159923)
(cherry picked from commit 6f439ee) Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
1 parent aa5b0ed commit cb6a4bb

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
@@ -531,6 +531,48 @@ Initializing and finalizing the interpreter
531531
first initialized).
532532
533533
534+
.. c:function:: int Py_FrozenMain(int argc, char **argv)
535+
536+
.. index:: single: freeze utility
537+
538+
The main program for a "frozen" Python program (an executable that embeds
539+
the interpreter together with the bytecode of the program's modules, as
540+
produced by the :program:`freeze` utility; see :source:`Tools/freeze`).
541+
542+
This function initializes the interpreter, imports the frozen module named
543+
``__main__``, and finalizes the interpreter.
544+
The frozen modules must have been registered in
545+
:c:var:`PyImport_FrozenModules` before calling this function;
546+
it is a fatal error if ``__main__`` is not among them.
547+
548+
*argc* and *argv* are byte strings like the arguments of a C program's
549+
``main`` function, and are passed to the interpreter with
550+
:c:func:`PyConfig_SetBytesArgv`.
551+
Unlike :c:func:`Py_Main`, the arguments are not parsed as Python command
552+
line options (:c:member:`PyConfig.parse_argv` is ``0``), so all of them
553+
are made available to the program in :data:`sys.argv`.
554+
Apart from that, the interpreter uses the
555+
:ref:`Python Configuration <init-python-config>`, so environment variables
556+
such as :envvar:`PYTHONPATH` are honored.
557+
Warnings about the path configuration
558+
(:c:member:`PyConfig.pathconfig_warnings`) are suppressed.
559+
If :envvar:`PYTHONINSPECT` is set and standard input is a terminal, an
560+
interactive prompt is run after ``__main__`` has finished, as with the
561+
:option:`-i` option.
562+
563+
Return ``0`` if ``__main__`` ran without an unhandled exception, ``1``
564+
otherwise, and ``120`` if finalizing the interpreter failed (see
565+
:c:func:`Py_FinalizeEx`).
566+
An unhandled :exc:`SystemExit` terminates the process.
567+
If the interpreter cannot be initialized, the process exits via
568+
:c:func:`Py_ExitStatusException`.
569+
570+
On Windows, this function is not exported by the Python DLL.
571+
The :program:`freeze` utility compiles :file:`Python/frozenmain.c` into the
572+
frozen program instead, together with the Windows-specific hooks that the
573+
function requires.
574+
575+
534576
.. c:function:: int Py_RunMain(void)
535577
536578
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
@@ -55,8 +55,6 @@ PyDescr_COMMON
5555
PyDescr_NAME
5656
PyDescr_TYPE
5757
PyWrapperFlag_KEYWORDS
58-
# cpython/pylifecycle.h
59-
Py_FrozenMain
6058
# cpython/objimpl.h
6159
PyObject_GET_WEAKREFS_LISTPTR
6260
# cpython/pythonrun.h

0 commit comments

Comments
 (0)