Handle a signal: Difference between revisions

Content added Content deleted
m (added missing </lang>)
Line 817: Line 817:


<lang Julia>
<lang Julia>
ccall(:jl_exit_on_sigint, Void, (Cint,), 0)
ccall(:jl_exit_on_sigint, Cvoid, (Cint,), 0)

tic()
function timeit()
ticks = 0
ticks = 0
try
try
while true
while true
sleep(0.5)
sleep(0.5)
ticks += 1
ticks += 1
println(ticks)
println(ticks)
end
catch
end
end
end
end

println()
@time timeit()
toc()
println("Done.")
</lang>
</lang>
The tricky bit for this task is the <code>ccall</code>, which tells the <code>main()</code> running Julia to pass SIGINT on to Julia as an error. This call is not needed when running this code in Julia's REPL, which has the desired behavior by default.
The tricky bit for this task is the <code>ccall</code>, which tells the <code>main()</code> running Julia to pass SIGINT on to Julia as an error. This call is not needed when running this code in Julia's REPL, which has the desired behavior by default.

{{out}}
{{out}}
<pre>
<pre>
Line 843: Line 846:
8
8
9
9
10
^C
11
elapsed time: 4.689995572 seconds
6.020844 seconds (32.06 k allocations: 1.658 MiB)
Done.
</pre>
</pre>