Handle a signal: Difference between revisions

m
m (added missing </lang>)
Line 817:
 
<lang Julia>
ccall(:jl_exit_on_sigint, VoidCvoid, (Cint,), 0)
 
tic()
function timeit()
ticks = 0
try
while true
sleep(0.5)
ticks += 1
println(ticks)
end
catch
end
end
 
println()
@time timeit()
toc()
println("Done.")
</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.
 
{{out}}
<pre>
Line 843 ⟶ 846:
8
9
10
^C
11
elapsed time: 4.689995572 seconds
6.020844 seconds (32.06 k allocations: 1.658 MiB)
Done.
</pre>
 
4,105

edits