Skip to content

disable_sigint() throws SIGINT away rather than defers it. #1046

@alicedb2

Description

@alicedb2

I'm running a MCMC algorithm with the following basic structure. I'm using Julia 1.7.2 on MacOS.

try
    while true
        disable_sigint() do
            for i in 1:5
                # Slow, critical, interrupt unsafe code
                sleep(1)
                print(".")
            end
        end
        
        # Fast, interrupt safe code
        println("\nnow it is safe to interrupt immediately")
    end
catch InterruptException
    println("interrupt catched")
end

Despite pressing [I],[I] or clicking "Interrupt Kernel" in the kernel menu this code never interrupts. Given the next scenario I think it would work if I had superhuman reflexes and were able to hit [I], [I] exactly during the few microseconds of fast code outside the do-block.

Alternatively, if instead of wrapping the whole thing into a while-true I put a slow block of code outside the disable_sigint() block like so

try
    disable_sigint() do
        for i in 1:5
            sleep(1)
            print(".")
        end
    end

    # Slow, interrupt safe code
    println("\nnow it is safe to interrupt immediately")

    while true
        sleep(1)
        print("*")
    end
catch InterruptException
    println("interrupt catched")
end

then I can interrupt the code by hitting [I], [I] when inside the slow while-true block. If I hit [I], [I] while inside the `do-block' nothing happens and SIGINT is apparently thrown away and not deferred to the slow part.

I tested the exact same code in both cases in the base REPL and it works as expected. When hitting Ctrl+C the SIGINT is queued and deferred until just outside the do-block and the InterruptException is caught.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions