-
-
Notifications
You must be signed in to change notification settings - Fork 34.1k
gh-144748: Make PyErr_CheckSignals raise the exception scheduled by PyThreadState_SetAsyncExc #145178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
gh-144748: Make PyErr_CheckSignals raise the exception scheduled by PyThreadState_SetAsyncExc #145178
Changes from all commits
da5c286
2f6139f
b47b9e8
9c23743
99040b6
ac8cf87
2293148
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| :c:func:`PyErr_CheckSignals` now raises the exception scheduled by | ||
| :c:func:`PyThreadState_SetAsyncExc`, if any. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| #include "parts.h" | ||
| #include "util.h" | ||
|
|
||
| static PyObject * | ||
| threadstate_set_async_exc(PyObject *module, PyObject *args) | ||
| { | ||
| unsigned long id; | ||
| PyObject *exc; | ||
| if (!PyArg_ParseTuple(args, "kO", &id, &exc)) { | ||
| return NULL; | ||
| } | ||
| int result = PyThreadState_SetAsyncExc(id, exc); | ||
| return PyLong_FromLong(result); | ||
| } | ||
|
|
||
| static PyMethodDef test_methods[] = { | ||
| {"threadstate_set_async_exc", threadstate_set_async_exc, METH_VARARGS, NULL}, | ||
| {NULL}, | ||
| }; | ||
|
|
||
| int | ||
| _PyTestLimitedCAPI_Init_ThreadState(PyObject *m) | ||
| { | ||
| return PyModule_AddFunctions(m, test_methods); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1423,11 +1423,7 @@ _Py_HandlePending(PyThreadState *tstate) | |
|
|
||
| /* Check for asynchronous exception. */ | ||
| if ((breaker & _PY_ASYNC_EXCEPTION_BIT) != 0) { | ||
| _Py_unset_eval_breaker_bit(tstate, _PY_ASYNC_EXCEPTION_BIT); | ||
| PyObject *exc = _Py_atomic_exchange_ptr(&tstate->async_exc, NULL); | ||
| if (exc != NULL) { | ||
| _PyErr_SetNone(tstate, exc); | ||
| Py_DECREF(exc); | ||
| if (_PyEval_RaiseAsyncExc(tstate) < 0) { | ||
| return -1; | ||
| } | ||
| } | ||
|
|
@@ -1438,3 +1434,18 @@ _Py_HandlePending(PyThreadState *tstate) | |
|
|
||
| return 0; | ||
| } | ||
|
|
||
| int | ||
| _PyEval_RaiseAsyncExc(PyThreadState *tstate) | ||
| { | ||
encukou marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| assert(tstate != NULL); | ||
| assert(tstate == _PyThreadState_GET()); | ||
| _Py_unset_eval_breaker_bit(tstate, _PY_ASYNC_EXCEPTION_BIT); | ||
| PyObject *exc = _Py_atomic_exchange_ptr(&tstate->async_exc, NULL); | ||
| if (exc != NULL) { | ||
| _PyErr_SetNone(tstate, exc); | ||
| Py_DECREF(exc); | ||
|
Comment on lines
+1446
to
+1447
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens if
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The usual C error checking message: Supporting instances would be a reasonable feature, but I haven't seen anyone asking for it. |
||
| return -1; | ||
| } | ||
| return 0; | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.