stack=traceback.format_stack()
Cython only generates the traceback as it propagates an exception upwards. So format_stack definitely doesn't work because there's nothing to inspect at this point.
e.g.
def f1():
raise RuntimeError()
def f2():
f1()
def f3():
try:
f2()
except RuntimeError as e:
...
def f4():
f3()
If you call f4 then eventually the RuntimeError is caught in f3().
That exception has a traceback (which you can look at). The
traceback contains f1, f2, and f3, but doesn't know that it was
called from f4.
This is the limit of Cython's handling of tracebacks.
David