Interpreter initialization and finalization — Python 3.14.7 documentation

docs.python.org

Tin mới

Thread states and the global interpreter lock

Python Module Index

3.14.7 Documentation

Python/C API reference manual

Python Initialization Configuration

See Python Initialization Configuration for details on how to configure the interpreter prior to initialization.

PyImport_AppendInittab()

PyMem_SetAllocator()

command line options

Python has variables for the global configuration to control different features and options. By default, these flags are controlled by command line options.

filesystem encoding and error handler

This API is kept for backward compatibility: setting PyPreConfig.legacy_windows_fs_encoding should be used instead, see Python Initialization Configuration.

sys: Access system-specific parameters and functions.

This API is kept for backward compatibility: setting PyConfig.legacy_windows_stdio should be used instead, see Python Initialization Configuration.

site: Module responsible for site-specific configuration.

This API is kept for backward compatibility: setting PyConfig.site_import should be used instead, see Python Initialization Configuration.

builtins: The module that provides the built-in namespace.

Initialize the Python interpreter. In an application embedding Python, this should be called before using any other Python/C API functions; see Before Python Initialization for the few exceptions.

__main__: The environment where top-level code is run. Covers command-line interfaces, import-time behavior, and ``__name__ == '__main__'``.

Initialize the Python interpreter. In an application embedding Python, this should be called before using any other Python/C API functions; see Before Python Initialization for the few exceptions.

Py_NewInterpreter()

Undo all initializations made by Py_Initialize() and subsequent use of Python/C API functions, and destroy all sub-interpreters (see Py_NewInterpreter() below) that were created and not yet destroyed since the last call

atexit: Register and execute cleanup functions.

Undo all initializations made by Py_Initialize() and subsequent use of Python/C API functions, and destroy all sub-interpreters (see Py_NewInterpreter() below) that were created and not yet destroyed since the last call

Cautions regarding runtime finalization¶

In the late stage of interpreter shutdown, after attempting to wait for non-daemon threads to exit (though this can be interrupted by KeyboardInterrupt) and running the atexit functions, the runtime is marked as finalizi

virtual environments

Deprecated since version 3.13, will be removed in version 3.15: Use PyConfig_Get("base_prefix") (sys.base_prefix) instead. Use PyConfig_Get("prefix") (sys.prefix) if virtual environments need to be handled.