From f6b39345f718b3ea9e6d01e9e71c6265a8511e58 Mon Sep 17 00:00:00 2001 From: rdb Date: Sun, 7 Feb 2021 12:30:15 +0100 Subject: [PATCH] event: don't exit task if future __await__ yields None This matches the behavior of asyncio's Task implementation, where this is the equivalent of `yield Task.cont`. I've kept regular generator tasks unaffected for now, since this might break existing usage. --- panda/src/event/pythonTask.cxx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/panda/src/event/pythonTask.cxx b/panda/src/event/pythonTask.cxx index e6183c56dd..f9295b7aaf 100644 --- a/panda/src/event/pythonTask.cxx +++ b/panda/src/event/pythonTask.cxx @@ -585,6 +585,11 @@ do_python_task() { return DS_done; } + } else if (result == Py_None && PyCoro_CheckExact(_generator)) { + // Bare yield from a coroutine means to try again next frame. + Py_DECREF(result); + return DS_cont; + } else if (DtoolInstance_Check(result)) { // We are waiting for an AsyncFuture (eg. other task) to finish. AsyncFuture *fut = (AsyncFuture *)DtoolInstance_UPCAST(result, Dtool_AsyncFuture);