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

Skip to content
Prev Previous commit
Next Next commit
Add Blurb and fix a refleak before anybody notices
  • Loading branch information
ambv committed Oct 12, 2023
commit 1ef282b75e78dce1cc035a24746a49c5c2eaae04
16 changes: 16 additions & 0 deletions Doc/using/cmdline.rst
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,10 @@ Miscellaneous options
This option may be useful for users who need to limit CPU resources of a
container system. See also :envvar:`PYTHON_CPU_COUNT`.
If *n* is ``default``, nothing is overridden.
* :samp:`-X presite={package.module}` specifies a module that should be
imported before ``site.py`` is executed. Python needs to be
:ref:`built in debug mode <debug-build>` for this option to exist.
See also :envvar:`PYTHON_PRESITE <PYTHON_PRESITE=package.module>`.

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

The ``-X presite`` option.


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

.. versionadded:: 3.11

.. envvar:: PYTHON_PRESITE=package.module
Comment thread
ambv marked this conversation as resolved.
Outdated

If this variable is set to a module, that module will be imported
early in the interpreter lifecycle, before ``site.py`` is executed.

See also the :option:`-X presite <-X>` command-line option,
which takes precedence over this variable.

.. versionadded:: 3.13
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Add :envvar:`PYTHON_PRESITE=package.module` to import a module early in the
interpreter lifecycle before ``site.py`` is executed. Python needs to be
:ref:`built in debug mode <debug-build>` for this option to exist.
3 changes: 3 additions & 0 deletions Python/initconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,9 @@ static const char usage_envvars[] =
#ifdef Py_STATS
"PYTHONSTATS : turns on statistics gathering\n"
#endif
#ifdef Py_DEBUG
"PYTHON_PRESITE=pkg.mod : import this module before site.py is run\n"
#endif
;

#if defined(MS_WINDOWS)
Expand Down
3 changes: 2 additions & 1 deletion Python/pylifecycle.c
Original file line number Diff line number Diff line change
Expand Up @@ -1170,10 +1170,11 @@ init_interp_main(PyThreadState *tstate)
else {
PyObject *presite = PyImport_Import(presite_modname);
if (presite == NULL) {
fprintf(stderr, "pre-site import failed; traceback:\n");
fprintf(stderr, "pre-site import failed:\n");
_PyErr_Print(tstate);
}
Py_XDECREF(presite);
Py_DECREF(presite_modname);
}
}
#endif
Expand Down