Skip to content

Commit

Permalink
Don't print C errors in err_handler if PyErr_Occurred() is True
Browse files Browse the repository at this point in the history
  • Loading branch information
c-randall committed Dec 20, 2024
1 parent 32cd430 commit 141e5bc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/sksundae/_cy_cvode.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions src/sksundae/_cy_ida.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 141e5bc

Please sign in to comment.