Interrupting execution

I have read that julia only checks for IO and signals etc at certain points in the code. How was I able to interrupt this execution with ctrl-c? Where can I read the details?

julia> function f()
           while true
           end
       end
f (generic function with 1 method)
julia> @code_llvm f()
;  @ REPL[1]:1 within `f'
; Function Attrs: noreturn
define nonnull {}* @julia_f_690() #0 {
top:
  br label %L1

L1:                                               ; preds = %L1, %top
;  @ REPL[1]:3 within `f'
  br label %L1
}

julia> f()
^C^C^C^C^C^C^CWARNING: Force throwing a SIGINT
ERROR: ^C^C^C^CInterruptException:^C
Stacktrace:
 [1] f()
   @ Main ./REPL[1]:3
 [2] top-level scope
   @ REPL[3]:1

The story is different outside the REPL

matt@pig:~$ cat /tmp/t.jl
while true end
matt@pig:~$ julia /tmp/t.jl
^C
signal (2): Interrupt
in expression starting at /tmp/t.jl:1
pthread_cond_wait at /lib/x86_64-linux-gnu/libpthread.so.0 (unknown line)
uv_cond_wait at /workspace/srcdir/libuv/src/unix/thread.c:847
jl_task_get_next at /buildworker/worker/package_linux64/build/src/partr.c:508
poptask at ./task.jl:760
wait at ./task.jl:769
task_done_hook at ./task.jl:494
_jl_invoke at /buildworker/worker/package_linux64/build/src/gf.c:2237 [inlined]
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2419
jl_apply at /buildworker/worker/package_linux64/build/src/julia.h:1703 [inlined]
jl_finish_task at /buildworker/worker/package_linux64/build/src/task.c:208
jl_threadfun at /buildworker/worker/package_linux64/build/src/partr.c:264
start_thread at /lib/x86_64-linux-gnu/libpthread.so.0 (unknown line)
clone at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
unknown function (ip: (nil))

... snip the call stack, it is too big to post! ...

_jl_invoke at /buildworker/worker/package_linux64/build/src/gf.c:2237 [inlined]
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2419
exec_options at ./client.jl:285
_start at ./client.jl:485
jfptr__start_43689.clone_1 at /opt/julia-1.6.3/lib/julia/sys.so (unknown line)
_jl_invoke at /buildworker/worker/package_linux64/build/src/gf.c:2237 [inlined]
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2419
jl_apply at /buildworker/worker/package_linux64/build/src/julia.h:1703 [inlined]
true_main at /buildworker/worker/package_linux64/build/src/jlapi.c:560
repl_entrypoint at /buildworker/worker/package_linux64/build/src/jlapi.c:702
main at julia (unknown line)
__libc_start_main at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
unknown function (ip: 0x4007d8)
unknown function (ip: (nil))
Allocations: 607501 (Pool: 606982; Big: 519); GC: 1

It also interrupts outside the repl for me.

% echo 'function f() while true end end; f()' > 1.jl 
% julia 1.jl 
^C
signal (2): Interrupt
in expression starting at /tmp/tmp.rWqqM4iP2I/1.jl:1
f at /tmp/tmp.rWqqM4iP2I/1.jl:1
unknown function (ip: 0x7feb171e68ec)
_jl_invoke at /buildworker/worker/package_linux64/build/src/gf.c:2237 [inlined]
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2419
unknown function (ip: (nil))
unknown function (ip: (nil))
Allocations: 628874 (Pool: 628476; Big: 398); GC: 1

Hmm, if I leave it to run, it is uninterruptible until I give it a ^Z

matt@pig:~/bin$ julia /tmp/t.jl
^C^C^C^C^C^C^C^C^C^Z

And this behaviour is different, it is uninterruptible … unless I press multiple ^C in quick succession

matt@pig:~/bin$ julia -e "while true end"
^C^C^C^C^C^C^C^C^C^C^CWARNING: Force throwing a SIGINT
ERROR: ^CInterruptException:
Stacktrace:
 [1] top-level scope
   @ ./none:1

There are new tickets about Julia 1.7.0 ignoring signals

2 Likes