FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-103176: sys._current_exceptions() returns mapping to exception instances instead of exc_info tuples by iritkatriel · Pull Request #103177 · python/cpython · GitHub

/ cpython Public
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .py  (1) .rst  (3) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
4 changes: 4 additions & 0 deletions Doc/library/sys.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ always available.

.. audit-event:: sys._current_exceptions "" sys._current_exceptions

.. versionchanged:: 3.12
Each value in the dictionary is now a single exception instance, rather
than a 3-tuple as returned from ``sys.exc_info()``.

.. function:: breakpointhook()

This hook function is called by built-in :func:`breakpoint`. By default,
Expand Down
8 changes: 8 additions & 0 deletions Doc/whatsnew/3.12.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,10 @@ sys
:data:`sys.last_type`, :data:`sys.last_value` and :data:`sys.last_traceback`.
(Contributed by Irit Katriel in :gh:`102778`.)

* :func:`sys._current_exceptions` now returns a mapping from thread-id to an
exception instance, rather than to a ``(typ, exc, tb)`` tuple.
(Contributed by Irit Katriel in :gh:`103176`.)


Optimizations
=============
Expand Down Expand Up @@ -844,6 +848,10 @@ Changes in the Python API
synchronization is needed, implement locking within the cached property getter
function or around multi-threaded access points.

* :func:`sys._current_exceptions` now returns a mapping from thread-id to an
exception instance, rather than to a ``(typ, exc, tb)`` tuple.
(Contributed by Irit Katriel in :gh:`103176`.)


Build Changes
=============
Expand Down
6 changes: 3 additions & 3 deletions Lib/test/test_sys.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -532,13 +532,13 @@ def g456():
main_id = threading.get_ident()
self.assertIn(main_id, d)
self.assertIn(thread_id, d)
self.assertEqual((None, None, None), d.pop(main_id))
self.assertEqual(None, d.pop(main_id))

# Verify that the captured thread frame is blocked in g456, called
# from f123. This is a little tricky, since various bits of
# threading.py are also in the thread's call stack.
exc_type, exc_value, exc_tb = d.pop(thread_id)
stack = traceback.extract_stack(exc_tb.tb_frame)
exc_value = d.pop(thread_id)
stack = traceback.extract_stack(exc_value.__traceback__.tb_frame)
for i, (filename, lineno, funcname, sourceline) in enumerate(stack):
if funcname == "f123":
break
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
:func:`sys._current_exceptions` now returns a mapping from thread-id to an
exception instance, rather than to a ``(typ, exc, tb)`` tuple.
13 changes: 6 additions & 7 deletions Python/pystate.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1998,14 +1998,13 @@ _PyThread_CurrentExceptions(void)
if (id == NULL) {
goto fail;
}
PyObject *exc_info = _PyErr_StackItemToExcInfoTuple(err_info);
if (exc_info == NULL) {
Py_DECREF(id);
goto fail;
}
int stat = PyDict_SetItem(result, id, exc_info);
PyObject *exc = err_info->exc_value;
assert(exc == NULL ||
exc == Py_None ||
PyExceptionInstance_Check(exc));

int stat = PyDict_SetItem(result, id, exc == NULL ? Py_None : exc);
Py_DECREF(id);
Py_DECREF(exc_info);
if (stat < 0) {
goto fail;
}
Expand Down

Back | FazBrowse Home | New Git URL