CTRL+C based interrupt doesn't work in VSCode

Hello, if I run a long simulation (example below) in VSCode, CTRL+C interrupt works (or doesn’t) depending on how I have started calling the main simulation function:

If I have mylongsimulation() (the function call) in a file and I am evaluating that row (CTRL+ENTER) in VSCode, the CTRL+C then doesn’t work/interrupt, while if I type the same call command in the VSCode associated Julia terminal, CTRL+C works as expected.

Is there a workaround to have CTRL+C working even if I run mylongsimulation() from the main VSCode file panel ?

Example of a long-running function:

function mylongsimulation()
    println("Starting long simulation...")
    for i1 in 1:100
        mylongssimulationinner1(i1)
    end
    println("Simulation complete")
end

function mylongssimulationinner1(i1)
    println("- Starting inner simulation 1 with i1 $i1...")
    for i2 in 1:10
        mylongssimulationinner2(i2)
    end
    return nothing
end

function mylongssimulationinner2(i2)
    println("-- Starting inner simulation 2 with i2 $i2...")
    for i in 1:10
        sleep(0.001)
    end
    return nothing
end

Got it.. for some reasons, if I am in the first case (running from the file editor) I need to use CTRL+C (capital C, i.e. CTRL+SHIFT+c)

FWIW, a very ugly workaround I use to stop long running calculations is to add something like

isfile("stop_file") && return 

Such that the long running calculations return if the file is found. That’s particularly useful for parallel runs, where Control C usually breaks everything.

1 Like