That's a good point regarding code gen and garbage collection, etc.. I should be able to work with this for now but definitely look forward to a safer first-class mechanism. Is there an issue opened for this on github?
On Tuesday, 17 June 2014 12:36:02 UTC-3, Stefan Karpinski wrote: > > There's very few things you can safely do in a signal handler. Calling a > julia function can potentially lead to code generation, GC, etc., all of > which is bad news in a signal handler. That's why we need a first-class > mechanism for this: install a Julia function as a handler and the system > arranges for your function to be called when the interrupt happens, but > safely. > > > On Tue, Jun 17, 2014 at 11:21 AM, Stephen Chisholm <sbchi...@gmail.com > <javascript:>> wrote: > >> I like the idea of an interrupt handling mechanism. What do you see that >> would make the signal/libc approach unreliable? >> >> >> On Tuesday, 17 June 2014 12:18:11 UTC-3, Stefan Karpinski wrote: >> >>> That is very unlikely to be reliable, but it's cool that it works. I >>> think that we probably should change SIGINT from raising a normal error to >>> triggering some kind of interrupt handling mechanism (which can in turn >>> raise an error by default). >>> >>> >>> On Tue, Jun 17, 2014 at 10:41 AM, Stephen Chisholm <sbchi...@gmail.com> >>> wrote: >>> >>>> I'm able to register a callback function using signal in libc, see the >>>> code below. >>>> >>>> SIGINT=2 >>>> >>>> function catch_function(x) >>>> println("caught signal $x") >>>> exit(0)::Nothing >>>> end >>>> catch_function_c = cfunction(catch_function, None, (Int64,)) >>>> ccall((:signal, "libc"), Void, (Int64, Ptr{Void}), SIGINT, >>>> catch_function_c) >>>> >>>> while true >>>> sleep(1) >>>> end >>>> >>>> >>>> >>>> On Tuesday, 17 June 2014 09:24:43 UTC-3, Stephen Chisholm wrote: >>>>> >>>>> I'm able to catch the InterruptException with the code below when >>>>> running in the REPL, but it doesn't seem to get thrown when running the >>>>> code in a script. >>>>> >>>>> while true >>>>> try sleep(1) >>>>> println("running...") >>>>> catch err >>>>> println("error: $err") >>>>> end >>>>> end >>>>> >>>>> >>>>> On Monday, 16 June 2014 18:30:36 UTC-3, Ivar Nesje wrote: >>>>>> >>>>>> SIGINT gets converted to a InterruptException, that can be caught in >>>>>> a catch statement. If you happened to be in a ccall, you might cause >>>>>> your >>>>>> program to be in a corrupt state and leak resources such as memory. >>>>>> >>>>>> I'm not sure how you can interact with other signals. >>>>>> >>>>> >>> >