Code intermittently not being interruptible

I’ve found that I sometimes can’t interrupt my code using ctrl-C or CMD-dot.

The following was working for me earlier today as a minimal example:

using Plots

function main()
    while true
        plt = plot(rand(100))


I was putting this in a file called mwe.jl and then running it with

julia -i mwe.jl

Pressing CMD-. or ctrl-C would print the characters “^C” to the screen but not interrupt the code. The only way I could stop it was by pressing ctrl-Z and then ending the stopped job - I couldn’t find any way to get back to the Julia prompt without starting a new julia process.

But then at some point it started working again, and now I can interrupt it as expected. I don’t know what I did that might have changed that. (I think what I did was remove the println to see if it would work without it. After that it seemed to work even with the println. But it doesn’t seem very likely that that would be what fixed the issue.)

Is this a known issue, and if so, is there anything I can do to guarantee that my code can be interrupted? It’s kind of annoying to have to suspend the job every time when interrupting decides not to work.

I’m on MacOS (version 12.6 Monterey) if that makes any difference, and running Julia 1.8.1.

not sure ,if there is a better way, but you can put a yield() somewhere in that loop.

(sorry for replying late, I missed your message.) I think I tried putting the yield() in the loop, with no effect, but the next time this happens I will make sure of that.