1.1、PyConfig简介 1.2、运行时配置config 2、文件读取与输入 2.1、通过-c输入 2.2、通过-m输入 2.3、通过文件输入 3、系列文章 1、运行时配置 上篇文章已经简单见过Python执行的流程,接下来详细的看下运行时配置相关的内容 1.1、PyConfig简介 在执行Python之前,需要对Python进行配置 在可以看到在pymain_init中可以看...
在文件Include/cpython/initconfig.h中名为PyConfig的对象会定义一个配置的数据结构。 配置数据结构包括以下内容: 各种模式的运行时标志,如调试和优化模式 执行模式,例如是否传递了文件名,提供了stdin或模块名称 扩展选项,由-X<Option> 运行时设置的环境变量 配置数据主要是CPython在运行时用于启用和禁用各种功能。Pyth...
在Python/initconfig.c中,建立了从环境变量和运行时命令行标志读取设置的逻辑。 在config_read_env_vars函数中,读取环境变量并用于为配置设置分配值:static PyStatus config_read_env_vars(PyConfig *config) { PyStatus status; int use_env = config->use_environment; /* 获取环境变量 */ _Py_get_env_...
PyConfig config; PyConfig_InitPythonConfig(&config); // 将命令行参数存储至 `config->argv` if (args->use_bytes_argv) { status = PyConfig_SetBytesArgv(&config, args->argc, args->bytes_argv); } else { status = PyConfig_SetArgv(&config, args->argc, args->wchar_argv); } if (_PyStat...
另外里面出现了一个PyStatus, 表示程序执行的状态, 会检测是否发生了异常,该结构体定义在Include/cpython/initconfig.h中。 typedefstruct{enum{_PyStatus_TYPE_OK=0, _PyStatus_TYPE_ERROR=1, _PyStatus_TYPE_EXIT=2} _type;constchar*func;constchar*err_msg;intexitcode; ...
bpo-38304: PyConfig_InitPythonConfig() cannot fail anymore (pythonGH-… Oct 1, 2019 Python [3.8] bpo-39427: Document -X opt options in the CLI --help and the ma… Feb 24, 2020 Tools bpo-38589: Fixes HTML Help shortcut when Windows is not installed to … Oct 29, 2019 m4 closes ...
If PYTHONISOLATED=1 and PYTHONEXECUTABLE is a valid path static bool initIsolated() { PyConfig config; PyConfig_InitIsolatedConfig(&config); auto [es, venv_executable] = PyRxINI::pythonvenv_path(); if (es == false) return false; auto status = PyConfig_SetString(&config, &config.executable...
Python/future.o \ Python/getargs.o \ Python/getcompiler.o \ Python/getcopyright.o \ Python/getplatform.o \ Python/getversion.o \ Python/hamt.o \ Python/hashtable.o \ Python/import.o \ Python/importdl.o \ Python/initconfig.o \ Python/marshal.o \ Python/modsupport....
7PEP 587:Python初始化配置 在PEP 587 添加了新的 C API 以配置 Python 初始化,从而提供了对整个配置的更好控制和更好的错误报告。 该PEP 还向这些内部结构添加了_PyRuntimeState.preconfig(PyPreConfig类型)和 PyInterpreterState.config(PyConfig类型)字段。PyInterpreterState.config 成为新的参考配置,替换全局配置...
Python/getplatform.o \ Python/getversion.o \ Python/graminit.o \ Python/hamt.o \ Python/import.o \ Python/importdl.o \ Python/initconfig.o \ Python/marshal.o \ Python/modsupport.o \ Python/mysnprintf.o \ Python/mystrtoul.o \ Python/pathconfig.o \ Python/peephole....