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 <sbchish...@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.
>>>
>>

Reply via email to