How to interrupt (not kill) julia from the REPL (again)?

ryofurue
Fri, 02 Jun 2023 05:01:26 +0000
General Usage

Instead of adding a question to the old thread

How to interrupt (not kill) julia from the REPL? General Usage

From the REPL, how do I interrupt execution of a function? Basically, I want to press some command key and cause it to throw an error that I can catch. For example: function interruptable_loop() try while not_done # some computation end catch println("function terminated by user") # cleanup end end From reading some old threads, I got the impression that (on Windows) pressing ctrl+c would do what I want. I find that it does nothing unless I press it four times ra…

from 2019 of almost the same title, I create a new Topic.

From the old thread, I learned that Ctrl-C doesn’t always work, for example, during I/O. So, my question is, how to specify the points where Ctrl-C is accepted?

while until_done
   # . . . Some julia code without I/O . . .
   # . . . If you must interrupt, you want to interrupt here. . . .
   func_doing_intensive_io()
   # . . . You want to allow interruption here, too . . .
end

I run a program like this on the REPL but I’ve never succeeded to interrupt it, perhaps because the program spends 99% of the time in I/O.

I tried something like this:

try
while until_done
   # . . . Some julia code without I/O . . .
   func_doing_intensive_io()
   sleep(2)
   # . . . . . .
end
catch e
   display(e)
   exit(1)
end

This one isn’t interruptible either. If sleep() is interruptible, the above code should work, I thought.

How are signals handled on REPL? Is there a mechanism like trap of Unix shells?

7 posts - 2 participants