From 141e5bc3116846b85747e63e875893f86f51a02a Mon Sep 17 00:00:00 2001 From: "Corey R. Randall" Date: Fri, 20 Dec 2024 12:14:44 -0700 Subject: [PATCH] Don't print C errors in err_handler if PyErr_Occurred() is True --- src/sksundae/_cy_cvode.pyx | 5 +++-- src/sksundae/_cy_ida.pyx | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/sksundae/_cy_cvode.pyx b/src/sksundae/_cy_cvode.pyx index a91fca1..f2831de 100644 --- a/src/sksundae/_cy_cvode.pyx +++ b/src/sksundae/_cy_cvode.pyx @@ -12,7 +12,7 @@ from typing import Callable, Iterable # Dependencies import numpy as np cimport numpy as np -from cpython.exc cimport PyErr_CheckSignals +from cpython.exc cimport PyErr_CheckSignals, PyErr_Occurred # Extern cdef headers from .c_cvode cimport * @@ -146,7 +146,8 @@ cdef void _err_handler(int line, const char* func, const char* file, decoded_func = func.decode("utf-8") decoded_msg = msg.decode("utf-8").replace(", ,", ",").strip() - print(f"\n[{decoded_func}, Error: {err_code}] {decoded_msg}\n") + if not PyErr_Occurred(): + print(f"\n[{decoded_func}, Error: {err_code}] {decoded_msg}\n") cdef class AuxData: diff --git a/src/sksundae/_cy_ida.pyx b/src/sksundae/_cy_ida.pyx index b20bb2a..18a6648 100644 --- a/src/sksundae/_cy_ida.pyx +++ b/src/sksundae/_cy_ida.pyx @@ -12,7 +12,7 @@ from typing import Callable, Iterable # Dependencies import numpy as np cimport numpy as np -from cpython.exc cimport PyErr_CheckSignals +from cpython.exc cimport PyErr_CheckSignals, PyErr_Occurred # Extern cdef headers from .c_ida cimport * @@ -148,7 +148,8 @@ cdef void _err_handler(int line, const char* func, const char* file, decoded_func = func.decode("utf-8") decoded_msg = msg.decode("utf-8").replace(", ,", ",").strip() - print(f"\n[{decoded_func}, Error: {err_code}] {decoded_msg}\n") + if not PyErr_Occurred(): + print(f"\n[{decoded_func}, Error: {err_code}] {decoded_msg}\n") cdef class AuxData: