mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Close #18957: The PYTHONFAULTHANDLER environment variable now only enables the
faulthandler module if the variable is non-empty. Same behaviour than other variables like PYTHONDONTWRITEBYTECODE.
This commit is contained in:
parent
9437d7a7fe
commit
8898350076
4 changed files with 42 additions and 16 deletions
|
@ -511,9 +511,9 @@ conflict.
|
||||||
|
|
||||||
.. envvar:: PYTHONDONTWRITEBYTECODE
|
.. envvar:: PYTHONDONTWRITEBYTECODE
|
||||||
|
|
||||||
If this is set, Python won't try to write ``.pyc`` or ``.pyo`` files on the
|
If this is set to a non-empty string, Python won't try to write ``.pyc`` or
|
||||||
import of source modules. This is equivalent to specifying the :option:`-B`
|
``.pyo`` files on the import of source modules. This is equivalent to
|
||||||
option.
|
specifying the :option:`-B` option.
|
||||||
|
|
||||||
|
|
||||||
.. envvar:: PYTHONHASHSEED
|
.. envvar:: PYTHONHASHSEED
|
||||||
|
@ -582,11 +582,11 @@ conflict.
|
||||||
|
|
||||||
.. envvar:: PYTHONFAULTHANDLER
|
.. envvar:: PYTHONFAULTHANDLER
|
||||||
|
|
||||||
If this environment variable is set, :func:`faulthandler.enable` is called
|
If this environment variable is set to a non-empty string,
|
||||||
at startup: install a handler for :const:`SIGSEGV`, :const:`SIGFPE`,
|
:func:`faulthandler.enable` is called at startup: install a handler for
|
||||||
:const:`SIGABRT`, :const:`SIGBUS` and :const:`SIGILL` signals to dump the
|
:const:`SIGSEGV`, :const:`SIGFPE`, :const:`SIGABRT`, :const:`SIGBUS` and
|
||||||
Python traceback. This is equivalent to :option:`-X` ``faulthandler``
|
:const:`SIGILL` signals to dump the Python traceback. This is equivalent to
|
||||||
option.
|
:option:`-X` ``faulthandler`` option.
|
||||||
|
|
||||||
.. versionadded:: 3.3
|
.. versionadded:: 3.3
|
||||||
|
|
||||||
|
|
|
@ -265,17 +265,33 @@ faulthandler._sigsegv()
|
||||||
# By default, the module should be disabled
|
# By default, the module should be disabled
|
||||||
code = "import faulthandler; print(faulthandler.is_enabled())"
|
code = "import faulthandler; print(faulthandler.is_enabled())"
|
||||||
args = (sys.executable, '-E', '-c', code)
|
args = (sys.executable, '-E', '-c', code)
|
||||||
# use subprocess module directly because test.script_helper adds
|
# don't use assert_python_ok() because it always enable faulthandler
|
||||||
# "-X faulthandler" to the command line
|
output = subprocess.check_output(args)
|
||||||
stdout = subprocess.check_output(args)
|
self.assertEqual(output.rstrip(), b"False")
|
||||||
self.assertEqual(stdout.rstrip(), b"False")
|
|
||||||
|
|
||||||
def test_sys_xoptions(self):
|
def test_sys_xoptions(self):
|
||||||
# Test python -X faulthandler
|
# Test python -X faulthandler
|
||||||
code = "import faulthandler; print(faulthandler.is_enabled())"
|
code = "import faulthandler; print(faulthandler.is_enabled())"
|
||||||
rc, stdout, stderr = assert_python_ok("-X", "faulthandler", "-c", code)
|
args = (sys.executable, "-E", "-X", "faulthandler", "-c", code)
|
||||||
stdout = (stdout + stderr).strip()
|
# don't use assert_python_ok() because it always enable faulthandler
|
||||||
self.assertEqual(stdout, b"True")
|
output = subprocess.check_output(args)
|
||||||
|
self.assertEqual(output.rstrip(), b"True")
|
||||||
|
|
||||||
|
def test_env_var(self):
|
||||||
|
# empty env var
|
||||||
|
code = "import faulthandler; print(faulthandler.is_enabled())"
|
||||||
|
args = (sys.executable, "-c", code)
|
||||||
|
env = os.environ.copy()
|
||||||
|
env['PYTHONFAULTHANDLER'] = ''
|
||||||
|
# don't use assert_python_ok() because it always enable faulthandler
|
||||||
|
output = subprocess.check_output(args, env=env)
|
||||||
|
self.assertEqual(output.rstrip(), b"False")
|
||||||
|
|
||||||
|
# non-empty env var
|
||||||
|
env = os.environ.copy()
|
||||||
|
env['PYTHONFAULTHANDLER'] = '1'
|
||||||
|
output = subprocess.check_output(args, env=env)
|
||||||
|
self.assertEqual(output.rstrip(), b"True")
|
||||||
|
|
||||||
def check_dump_traceback(self, filename):
|
def check_dump_traceback(self, filename):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -7,6 +7,13 @@ What's New in Python 3.4.0 Alpha 3?
|
||||||
|
|
||||||
Projected Release date: 2013-10-XX
|
Projected Release date: 2013-10-XX
|
||||||
|
|
||||||
|
Library
|
||||||
|
-------
|
||||||
|
|
||||||
|
- The :envvar:`PYTHONFAULTHANDLER` environment variable now only enables the
|
||||||
|
faulthandler module if the variable is non-empty. Same behaviour than other
|
||||||
|
variables like :envvar:`PYTHONDONTWRITEBYTECODE`.
|
||||||
|
|
||||||
Tests
|
Tests
|
||||||
-----
|
-----
|
||||||
|
|
||||||
|
|
|
@ -1048,8 +1048,11 @@ faulthandler_env_options(void)
|
||||||
{
|
{
|
||||||
PyObject *xoptions, *key, *module, *res;
|
PyObject *xoptions, *key, *module, *res;
|
||||||
_Py_IDENTIFIER(enable);
|
_Py_IDENTIFIER(enable);
|
||||||
|
char *p;
|
||||||
|
|
||||||
if (!Py_GETENV("PYTHONFAULTHANDLER")) {
|
if (!((p = Py_GETENV("PYTHONFAULTHANDLER")) && *p != '\0')) {
|
||||||
|
/* PYTHONFAULTHANDLER environment variable is missing
|
||||||
|
or an empty string */
|
||||||
int has_key;
|
int has_key;
|
||||||
|
|
||||||
xoptions = PySys_GetXOptions();
|
xoptions = PySys_GetXOptions();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue