Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capture SIGINT with @async, in a script or in the REPL #45055

Open
chunjiw opened this issue Apr 21, 2022 · 5 comments
Open

Capture SIGINT with @async, in a script or in the REPL #45055

chunjiw opened this issue Apr 21, 2022 · 5 comments

Comments

@chunjiw
Copy link

chunjiw commented Apr 21, 2022

Define this function in REPL:

julia> function try_interrupt()
           while true
               try
                   sleep(1)
                   println("trying...")
                   @async 1+1
               catch e
                   if typeof(e) <: InterruptException
                       println("caught Interrupt")
                       return
                   end
               end
           end
           return
       end
try_interrupt (generic function with 1 method)

In Julia 1.7.2, everything works:

julia> try_interrupt()
trying...
trying...
^Ccaught Interrupt

julia> versioninfo()
Julia Version 1.7.2
Commit bf53498635 (2022-02-06 15:21 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i7-6850K CPU @ 3.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.1 (ORCJIT, broadwell)

But in 1.9.0 it does not work:

julia> versioninfo()
Julia Version 1.9.0-DEV.426
Commit 4dfef57535 (2022-04-21 19:14 UTC)
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 12 × Intel(R) Core(TM) i7-6850K CPU @ 3.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-13.0.1 (ORCJIT, broadwell)
  Threads: 1 on 12 virtual cores

julia> try_interrupt()
trying...
trying...
^Cfatal: error thrown and no exception handler available.
InterruptException()
jl_mutex_unlock at /home/chunjiw/projects/playground/buildjulia/julia/src/julia_locks.h:129 [inlined]
ijl_task_get_next at /home/chunjiw/projects/playground/buildjulia/julia/src/partr.c:382
poptask at ./task.jl:931
wait at ./task.jl:940
task_done_hook at ./task.jl:640
jfptr_task_done_hook_61719 at /home/chunjiw/projects/playground/buildjulia/julia/usr/lib/julia/sys.so (unknown line)
jl_apply at /home/chunjiw/projects/playground/buildjulia/julia/src/julia.h:1838 [inlined]
jl_finish_task at /home/chunjiw/projects/playground/buildjulia/julia/src/task.c:254
start_task at /home/chunjiw/projects/playground/buildjulia/julia/src/task.c:942

In another word, issue #19467 comes back.

If I put the code in a script file.jl, then run it with

  • julia -i file.jl or
  • julia -e 'include(popfirst!(ARGS))' file.jl,
    then both 1.7.2 and 1.9.0 returns fatal error when attempt to interrupt with Ctrl-C: fatal: error thrown and no exception handler available.

Note: using Base.exit_on_sigint(false) does not solve this issue

@chunjiw
Copy link
Author

chunjiw commented Apr 21, 2022

I'm not sure how this is related to #40416 or #35524

@arnaudh
Copy link

arnaudh commented Jan 10, 2023

Just coming to say I'm bumping into the same issue. I'm running multiple AWS.jl calls in an asyncmap, and Ctrl-C kills the REPL with the same C stack trace as in this issue. The example in this issue seems to also be the MWE for my case. Note I'm on 1.8.3.

julia> versioninfo()
Julia Version 1.8.3
Commit 0434deb161e (2022-11-14 20:14 UTC)
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 8 × Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-13.0.1 (ORCJIT, skylake-avx512)
  Threads: 1 on 8 virtual cores

@chunjiw
Copy link
Author

chunjiw commented Dec 27, 2023

With just released 1.10.0, this issue is gone in the REPL, but persists in scripting.

@nsajko
Copy link
Contributor

nsajko commented Dec 31, 2023

Reproducible on the master branch. Changing the @async to Threads.@spawn and adding synchronization still results in the same issue:

/tmp/file.jl:

function try_interrupt()
    @sync while true
        br = try
            sleep(1)
            println("trying...")
            Threads.@spawn 1+1
            false
        catch e
            if typeof(e) <: InterruptException
                println("caught Interrupt")
                true
            else
                false
            end
        end::Bool
        br && break
    end
end

try_interrupt()

Results in:

$ ./build_master/julia -g2 /tmp/file.jl 
trying...
trying...
^C
[103873] signal 2: Interrupt
in expression starting at /tmp/file.jl:20
epoll_wait at /usr/lib/libc.so.6 (unknown line)
uv__io_poll at /workspace/srcdir/libuv/src/unix/epoll.c:236
uv_run at /workspace/srcdir/libuv/src/unix/core.c:400
ijl_task_get_next at /home/nsajko/tmp/jl/jl/julia-git/src/scheduler.c:514
poptask at ./task.jl:998
wait at ./task.jl:1007
task_done_hook at ./task.jl:687
jfptr_task_done_hook_59818 at /home/nsajko/tmp/jl/jl/julia-git/build_master/usr/lib/julia/sys.so (unknown line)
jl_apply at /home/nsajko/tmp/jl/jl/julia-git/src/julia.h:2152 [inlined]
jl_finish_task at /home/nsajko/tmp/jl/jl/julia-git/src/task.c:327
start_task at /home/nsajko/tmp/jl/jl/julia-git/src/task.c:1317
unknown function (ip: (nil))
Allocations: 1 (Pool: 1; Big: 0); GC: 0

@Thuener
Copy link

Thuener commented Nov 19, 2024

This is still an issue?
For me it works on version 1.10.2:

julia> function try_interrupt()
                  while true
                      try
                          sleep(1)
                          println("trying...")
                          @async 1+1
                      catch e
                          if typeof(e) <: InterruptException
                              println("caught Interrupt")
                              return
                          end
                      end
                  end
                  return
              end
try_interrupt (generic function with 1 method)

julia> try_interrupt()
trying...
trying...
caught Interrupt

julia>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants