refactoring: fix deprecated sys.last (#5573)

* fix deprecated

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix deprecated

* fix deprecated

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix deprecated

* fix deprecated

---------

Co-authored-by: a <1@1.1>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Andy Kipp 2024-07-04 11:04:15 +02:00 committed by GitHub
parent 4e06328bec
commit b6d8d3d823
Failed to generate hash of commit

View file

@ -1055,7 +1055,17 @@ def print_exception(msg=None, exc_info=None, source_msg=None):
limit = 0
chain = False
sys.last_exc = exc_info
if xsh.env.get("XONSH_SHOW_TRACEBACK", False):
"""
This moved under ``XONSH_SHOW_TRACEBACK`` because it looks that python's
internal machinery behind ``sys.last_*`` is not thread safe
when traceback is not printed (#5408).
"""
if sys.version_info >= (3, 12):
# https://docs.python.org/3/library/sys.html#sys.last_exc
sys.last_exc = exc_info
else:
sys.last_type, sys.last_value, sys.last_traceback = exc_info
manually_set_trace, show_trace = _get_manual_env_var("XONSH_SHOW_TRACEBACK", False)
manually_set_logfile, log_file = _get_manual_env_var("XONSH_TRACEBACK_LOGFILE")