From aa554a2130a2b22fef1acd70956a3f12e31d992d Mon Sep 17 00:00:00 2001 From: rdb Date: Thu, 28 Aug 2025 10:24:34 +0200 Subject: [PATCH] task: Backport fix for generators without send() Backport of 00b5357b8ebfe521851f296b7d555d3ba1cf16f6 --- panda/src/event/pythonTask.cxx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/panda/src/event/pythonTask.cxx b/panda/src/event/pythonTask.cxx index 8395bd5adc..4b3a79f7ef 100644 --- a/panda/src/event/pythonTask.cxx +++ b/panda/src/event/pythonTask.cxx @@ -534,9 +534,15 @@ do_python_task() { // We are calling a generator. Use "send" rather than PyIter_Next since // we need to be able to read the value from a StopIteration exception. PyObject *func = PyObject_GetAttrString(_generator, "send"); - nassertr(func != nullptr, DS_interrupt); - result = PyObject_CallFunctionObjArgs(func, Py_None, nullptr); - Py_DECREF(func); + if (func != nullptr) { + result = PyObject_CallOneArg(func, Py_None); + Py_DECREF(func); + } else { + // It has no send(), just call next() directly. + nassertr(Py_TYPE(_generator)->tp_iternext != nullptr, DS_interrupt); + PyErr_Clear(); + result = Py_TYPE(_generator)->tp_iternext(_generator); + } if (result == nullptr) { // An error happened. If StopIteration, that indicates the task has