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.
except RuntimeError as e:
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.