From 64366fa9b3ba71b8a503a8719eff433f4ea49eb9 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Mon, 2 Nov 2020 15:16:25 +0100 Subject: bpo-41435: Add sys._current_exceptions() function (GH-21689) This adds a new function named sys._current_exceptions() which is equivalent ot sys._current_frames() except that it returns the exceptions currently handled by other threads. It is equivalent to calling sys.exc_info() for each running thread. --- Python/sysmodule.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'Python/sysmodule.c') diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 749b96455d6..945e639ca57 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -1837,6 +1837,21 @@ sys__current_frames_impl(PyObject *module) return _PyThread_CurrentFrames(); } +/*[clinic input] +sys._current_exceptions + +Return a dict mapping each thread's identifier to its current raised exception. + +This function should be used for specialized purposes only. +[clinic start generated code]*/ + +static PyObject * +sys__current_exceptions_impl(PyObject *module) +/*[clinic end generated code: output=2ccfd838c746f0ba input=0e91818fbf2edc1f]*/ +{ + return _PyThread_CurrentExceptions(); +} + /*[clinic input] sys.call_tracing @@ -1953,6 +1968,7 @@ static PyMethodDef sys_methods[] = { METH_FASTCALL | METH_KEYWORDS, breakpointhook_doc}, SYS__CLEAR_TYPE_CACHE_METHODDEF SYS__CURRENT_FRAMES_METHODDEF + SYS__CURRENT_EXCEPTIONS_METHODDEF SYS_DISPLAYHOOK_METHODDEF SYS_EXC_INFO_METHODDEF SYS_EXCEPTHOOK_METHODDEF -- cgit v1.2.3