On Sat, Mar 13, 2010 at 2:30 PM, Robert Bradshaw <rober...@math.washington.edu> wrote: > On Mar 13, 2010, at 5:29 AM, Nicolas M. Thiery wrote: >> >> def bla(...): >> with sig_on: >> if ... >> raise ... >> elif ... >> return >> ...
This is exactly the required semantics. I didn't know cython supported with-guards. Are they lightweight enough? We really only want to add a call to _sig_on macro at start and a call to _sig_off macro at end, and no other bloat. the whole process should have very tiny overhead, except for the first call to _sig_on (when signal trapping is enabled: there must be a call to sigsetjmp(3) which is somehow costly). While nesting is not supported atm, it should, and nested calls to _sig_on should be almost overhead free as well. > Yes, for sure--I've been thinking about borrowing the with syntax as well. > Perhaps there could also be syntax/a decorator for marking an entire > function as getting and releasing the signal handler too (just as we have > with the GIL). As part of incorporating this into Cython, some syntactic > improvements should be considered. Any other ideas? What's the syntax for supporting the GIL? Something like that could work, I guess. Something along this lines: @with_sig_on def bla(...): if ... raise ... elif ... return ... Would be great (or whatever other syntax, like an attribute for the function, etc). The key point being that one can add or remove the "with_sig_on" without touching the function body. In the "with" syntax, the whole body needs to be reindented. Moreover, when there's a docstring, the "with" clause goes after the docstring, while the decorator syntax clearly displays at the top the fact that the function catches signals. The with clause is more flexible, though -- sometimes one wants to compute quickly (no signal catching) for small arguments (say you know the computation will be pretty fast) but catch the signals in other cases all in the same body. What are the options for supporting this (either the decorator/function attribute or the with-clause)? Gonzalo -- To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org