From 29f552a6ef3cc2e6c88a3df4e1e21c101bd50d62 Mon Sep 17 00:00:00 2001 From: rdb Date: Tue, 5 May 2020 14:35:43 +0200 Subject: [PATCH] task: Use TimeoutError from asyncio.exceptions on Python 3.8+ Fixes unit test failures --- panda/src/event/asyncFuture_ext.cxx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/panda/src/event/asyncFuture_ext.cxx b/panda/src/event/asyncFuture_ext.cxx index 96997b8135..f47abdf7db 100644 --- a/panda/src/event/asyncFuture_ext.cxx +++ b/panda/src/event/asyncFuture_ext.cxx @@ -196,16 +196,26 @@ result(PyObject *timeout) const { static PyObject *exc_type = nullptr; if (exc_type == nullptr) { // Get the TimeoutError that asyncio uses, too. +#if PY_VERSION_HEX >= 0x03080000 + PyObject *module = PyImport_ImportModule("asyncio.exceptions"); +#else PyObject *module = PyImport_ImportModule("concurrent.futures._base"); +#endif if (module != nullptr) { exc_type = PyObject_GetAttrString(module, "TimeoutError"); Py_DECREF(module); } // If we can't get that, we should pretend and make our own. if (exc_type == nullptr) { +#if PY_VERSION_HEX >= 0x03080000 + exc_type = PyErr_NewExceptionWithDoc((char*)"asyncio.exceptions.TimeoutError", + (char*)"The operation exceeded the given deadline.", + nullptr, nullptr); +#else exc_type = PyErr_NewExceptionWithDoc((char*)"concurrent.futures._base.TimeoutError", (char*)"The operation exceeded the given deadline.", nullptr, nullptr); +#endif } } PyErr_SetNone(exc_type);