Why Julia’s `Distributed.interrupt` terminates workers?

Viewed 169

I’m confused what the function Distributed.interrupt() does. Documentation says it will ‘interrupt the current executing task on the specified workers’ but it seems to terminate the workers as well.

Example:

using Distributed

addprocs(1)  # Adding one local worker 
my_worker = workers()[1]

# Check number of processes
println("Processes: ", nprocs())

# Define a function
@everywhere function just_sleep(time)
    println("Sleeping...")
    sleep(time)
end

# Execute on the worker
remote_do(just_sleep, my_worker, 100)

# Wait a bit and interrupt
sleep(5)
interrupt(my_worker)

# Check number of processes again
sleep(5)
println("Processes: ", nprocs())

I get this output

> julia testing.jl
Processes: 2
      From worker 2:    Sleeping...
Worker 2 terminated.
Processes: 1

I’m expecting to have the worker process #2 still alive and number of processes still two at the end. It does not even help adding exception handling to the body of just_sleep():

function just_sleep(time)
    println("Sleeping...")
    try
        sleep(time)
    catch e
        if isa(e, InterruptException)
            println("interrupted")
        else
            println(e)
        end
    end
end

Now interrupt() seems to behave like Distributed.rmprocs(). I have Julia 1.5.3 on Windows 10.


EDIT

I tried it also on WSL Ubuntu as well. There is a bit more info, but the worker also gets terminated

Processes: 2
      From worker 2:    Sleeping...
      From worker 2:    fatal: error thrown and no exception handler available.
      From worker 2:    InterruptException()
      From worker 2:    jl_mutex_unlock at /buildworker/worker/package_linux64/build/src/locks.h:144 [inlined]
      From worker 2:    jl_task_get_next at /buildworker/worker/package_linux64/build/src/partr.c:476
      From worker 2:    poptask at ./task.jl:704
      From worker 2:    wait at ./task.jl:712 [inlined]
      From worker 2:    task_done_hook at ./task.jl:442
      From worker 2:    _jl_invoke at /buildworker/worker/package_linux64/build/src/gf.c:2214 [inlined]
      From worker 2:    jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2398
      From worker 2:    jl_apply at /buildworker/worker/package_linux64/build/src/julia.h:1690 [inlined]
Worker 2 terminated.      From worker 2:        jl_finish_task at /buildworker/worker/package_linux64/build/src/task.c:196

      From worker 2:    start_task at /buildworker/worker/package_linux64/build/src/task.c:715
      From worker 2:    unknown function (ip: (nil))
Processes: 1

Interestingly, it works on an interactive REPL session (only on Linux):

Processes: 2
workers() = [2]
      From worker 2:    Sleeping for 100 s...
      From worker 2:    interrupted!
Processes: 2
workers() = [2]
1-element Array{Int64,1}:
 2
0 Answers
Related