Skip to content

Commit 57c563d

Browse files
[3.15] gh-141004: Document Py_FrozenMain (GH-159724) (GH-159922)
(cherry picked from commit 6f439ee) Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
1 parent 9653bdd commit 57c563d

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