On May 12, 4:17 pm, leif <not.rea...@online.de> wrote:

> It doesn't seem Python would execute *any* code of the custom (Python)
> handler (as opposed to just deferring the raise KeyboardInterrupt or
> what follows it) before the Cython function returns by other means.

Looking at the Python code base (and using common sense), I don't
think Python ever executes any python interpreter code *in the signal
handler*. Rather, the "signal occurred" information gets stored and
next time the interpreter gets around to it, all routines registered
with the relevant signal get executed, by then in the normal execution
context.

This still happens now as well: When the alarm arrives, the right data
gets set. If, in addition, a SIGINT arrives inside a sigon/sigoff, the
cython routine exits under exception conditions. However, as you see
from the message that gets processed, the signal condition is checked
by python before the exception condition and the signal handler code
gets executed and raises a KeyboardInterrupt with a custom message,
and that's the one that arrives.

So, one mode of operation would be:

Inside a sigon/sigoff, set the usual Python "signal occurred"
information. Furthermore, raise (as usual) an exception at the
outermost "sigon" active. That exception only serves the purpose as a
short path to the closes Python interpreter, which will process the
"signal occurred" information.

This would work slightly differently from the current sigon/sigoff
processing for SIGINT, which raises an exception but does not call
PyErr_SetInterrupt(), so presently, the signal gets processed as an
exception, not via Python's signal handling.

Incidentally, note:

sage: alarm(10); integrate(cos(x*sin(x)^10),x)
KeyboardInterrupt: computation timed out because alarm was set for 10
seconds

so somehow the SIGALRM gets reacted on properly by ECL (which has its
own signal handler) and somehow the condition arrives in its proper
state in Python as well, so that Python gets a turn at running the
registered signal handlers.

Cheers,

Nils

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to