Skip to content

Commit 0bc290e

Browse files
committed
event: Replace _PyGen_FetchStopIterationValue in Python 3.13+
See python/cpython#106320 and python/cpython#107032 Closes #1526
1 parent a463f25 commit 0bc290e

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

panda/src/event/pythonTask.cxx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,17 @@ do_python_task() {
545545
Py_DECREF(_generator);
546546
_generator = nullptr;
547547

548-
#if PY_VERSION_HEX >= 0x03030000
548+
#if PY_VERSION_HEX >= 0x030D0000 // Python 3.13
549+
// Python 3.13 does not support _PyGen_FetchStopIterationValue anymore.
550+
if (PyErr_ExceptionMatches(PyExc_StopIteration)) {
551+
PyObject *exc = PyErr_GetRaisedException();
552+
result = ((PyStopIterationObject *)exc)->value;
553+
if (result == nullptr) {
554+
result = Py_None;
555+
}
556+
Py_INCREF(result);
557+
Py_DECREF(exc);
558+
#elif PY_VERSION_HEX >= 0x03030000
549559
if (_PyGen_FetchStopIterationValue(&result) == 0) {
550560
#else
551561
if (PyErr_ExceptionMatches(PyExc_StopIteration)) {

0 commit comments

Comments
 (0)