Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1ef282b

Browse files
committed
Add Blurb and fix a refleak before anybody notices
1 parent 3daa65a commit 1ef282b

4 files changed

Lines changed: 24 additions & 1 deletion

File tree

Doc/using/cmdline.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,10 @@ Miscellaneous options
552552
This option may be useful for users who need to limit CPU resources of a
553553
container system. See also :envvar:`PYTHON_CPU_COUNT`.
554554
If *n* is ``default``, nothing is overridden.
555+
* :samp:`-X presite={package.module}` specifies a module that should be
556+
imported before ``site.py`` is executed. Python needs to be
557+
:ref:`built in debug mode <debug-build>` for this option to exist.
558+
See also :envvar:`PYTHON_PRESITE <PYTHON_PRESITE=package.module>`.
555559

556560
It also allows passing arbitrary values and retrieving them through the
557561
:data:`sys._xoptions` dictionary.
@@ -602,6 +606,8 @@ Miscellaneous options
602606
.. versionadded:: 3.13
603607
The ``-X cpu_count`` option.
604608

609+
The ``-X presite`` option.
610+
605611

606612
Options you shouldn't use
607613
~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -1100,3 +1106,13 @@ Debug-mode variables
11001106
Need Python configured with the :option:`--with-trace-refs` build option.
11011107

11021108
.. versionadded:: 3.11
1109+
1110+
.. envvar:: PYTHON_PRESITE=package.module
1111+
1112+
If this variable is set to a module, that module will be imported
1113+
early in the interpreter lifecycle, before ``site.py`` is executed.
1114+
1115+
See also the :option:`-X presite <-X>` command-line option,
1116+
which takes precedence over this variable.
1117+
1118+
.. versionadded:: 3.13
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Add :envvar:`PYTHON_PRESITE=package.module` to import a module early in the
2+
interpreter lifecycle before ``site.py`` is executed. Python needs to be
3+
:ref:`built in debug mode <debug-build>` for this option to exist.

Python/initconfig.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,9 @@ static const char usage_envvars[] =
305305
#ifdef Py_STATS
306306
"PYTHONSTATS : turns on statistics gathering\n"
307307
#endif
308+
#ifdef Py_DEBUG
309+
"PYTHON_PRESITE=pkg.mod : import this module before site.py is run\n"
310+
#endif
308311
;
309312

310313
#if defined(MS_WINDOWS)

Python/pylifecycle.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1170,10 +1170,11 @@ init_interp_main(PyThreadState *tstate)
11701170
else {
11711171
PyObject *presite = PyImport_Import(presite_modname);
11721172
if (presite == NULL) {
1173-
fprintf(stderr, "pre-site import failed; traceback:\n");
1173+
fprintf(stderr, "pre-site import failed:\n");
11741174
_PyErr_Print(tstate);
11751175
}
11761176
Py_XDECREF(presite);
1177+
Py_DECREF(presite_modname);
11771178
}
11781179
}
11791180
#endif

0 commit comments

Comments
 (0)