def foo(): cdef int n # Some long running code that gets compiled to pure C, e.g., while True: n = n + 1
Indeed, if you simply rewrite the above code as follows, then suddenly control-C will work fine!
def foo(): cdef int n _sig_on while True: n = n + 1 _sig_off
include "../ext/interrupt.pxi"
in your file,
where you give in quotes the relative directory
to SAGE_ROOT/devel/sage/sage/ext/interrupt.pxi
.
In addition to SIGINT, any code wrapped in _sig_on
and
_sig_off
also traps SIGABRT, SIGALRM, SIGSEV, and SIGFPE.
IMPORTANT NOTES:
_sig_off
without a corresponding _sig_on
, then control-C
later in the interpreter will segfault!
__init__
method of
a Cython extension class, or you'll get crashes.
_sig_check
instead of using
_sig_on
then _sig_off
.
See About this document... for information on suggesting changes.