From 06dffde0feeb0d17377b18804850ecab34806f09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=A4rkl?= Date: Fri, 23 Feb 2018 16:38:32 +0100 Subject: [PATCH] Fix error handling in Python API, minor cleanup --- src/python/cutter_ipykernel.py | 2 +- src/utils/PythonAPI.cpp | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/python/cutter_ipykernel.py b/src/python/cutter_ipykernel.py index aaf90535..bf9985ec 100644 --- a/src/python/cutter_ipykernel.py +++ b/src/python/cutter_ipykernel.py @@ -59,7 +59,7 @@ def launch_ipykernel(argv): def run_kernel(): app.kernel_class = CutterIPythonKernel - app.log_level = logging.DEBUG + #app.log_level = logging.DEBUG app.initialize(argv[3:]) app.start() diff --git a/src/utils/PythonAPI.cpp b/src/utils/PythonAPI.cpp index 4f41dfcc..e0ba13df 100644 --- a/src/utils/PythonAPI.cpp +++ b/src/utils/PythonAPI.cpp @@ -58,7 +58,9 @@ PyObject *api_internal_launch_ipykernel(PyObject *self, PyObject *args, PyObject if (!PyArg_ParseTuple(args, "O", &argvListObject) || !PyList_Check(argvListObject)) { - qWarning() << "Invalid args passed to api_internal_launch_ipykernel()."; + const char *msg = "Invalid args passed to api_internal_launch_ipykernel()."; + qWarning() << msg; + PyErr_SetString(PyExc_RuntimeError, msg); return nullptr; } @@ -81,7 +83,9 @@ PyObject *api_internal_kernel_interface_send_signal(PyObject *, PyObject *args) if (!PyArg_ParseTuple(args, "ll", &id, &signum)) { - qWarning() << "Invalid args passed to api_internal_kernel_interface_send_signal()."; + const char *msg = "Invalid args passed to api_internal_kernel_interface_send_signal()."; + qWarning() << msg; + PyErr_SetString(PyExc_RuntimeError, msg); return nullptr; } @@ -100,7 +104,9 @@ PyObject *api_internal_kernel_interface_poll(PyObject *, PyObject *args) if (!PyArg_ParseTuple(args, "l", &id)) { - qWarning() << "Invalid args passed to api_internal_kernel_interface_poll()."; + const char *msg = "Invalid args passed to api_internal_kernel_interface_poll()."; + qWarning() << msg; + PyErr_SetString(PyExc_RuntimeError, msg); return nullptr; } @@ -130,14 +136,13 @@ PyObject *api_internal_thread_set_async_exc(PyObject *, PyObject *args) if (!PyArg_ParseTuple(args, "lO", &id, &exc)) { - qWarning() << "Invalid args passed to api_internal_set_async_exc()."; + const char *msg = "Invalid args passed to api_internal_thread_set_async_exc()."; + qWarning() << msg; + PyErr_SetString(PyExc_RuntimeError, msg); return nullptr; } - printf("setasyncexc %ld\n", id); int ret = PyThreadState_SetAsyncExc(id, exc); - printf("%d threads affected\n", ret); - return PyLong_FromLong(ret); }