# \#interruptexception

**URL:** https://discourse.julialang.org/tag/interruptexception/1497.md

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

---

## [Catch ctrl-c in script](https://discourse.julialang.org/t/catch-ctrl-c-in-script/119885)

<div class="topic-metadata">

**Author:** [@matthew3245](https://discourse.julialang.org/u/matthew3245)\
**Replies:** 2\
**Last updated:** [September 27, 2024, 1:11am UTC](https://discourse.julialang.org/t/catch-ctrl-c-in-script/119885 "2024-09-27T01:11:35Z")

</div>

From the Julia docs: Running a Julia script using julia file.jl does not throw InterruptException when you try to terminate it with CTRL-C (SIGINT). To run a certain code before terminating a Julia script, which may or…

---

## [Cannot catch Ctrl-C gracefully in this script](https://discourse.julialang.org/t/cannot-catch-ctrl-c-gracefully-in-this-script/79757)

<div class="topic-metadata">

**Author:** [@chunjiw](https://discourse.julialang.org/u/chunjiw)\
**Replies:** 12\
**Last updated:** [December 31, 2023, 10:54am UTC](https://discourse.julialang.org/t/cannot-catch-ctrl-c-gracefully-in-this-script/79757 "2023-12-31T10:54:03Z")

</div>

This is related to this issue. Put the following into a script file.jl: function try\_interrupt() while true try sleep(1) println("trying...") @async 1+1 catch e …

---

## [Graceful interruption and ensure finishing current loop](https://discourse.julialang.org/t/graceful-interruption-and-ensure-finishing-current-loop/92359)

<div class="topic-metadata">

**Author:** [@AllanChain](https://discourse.julialang.org/u/AllanChain)\
**Replies:** 0\
**Last updated:** [December 31, 2022, 1:30pm UTC](https://discourse.julialang.org/t/graceful-interruption-and-ensure-finishing-current-loop/92359 "2022-12-31T13:30:53Z")

</div>

I have a big for loop but each step only takes a few secs to finish. What I want is that when I press Ctrl+C, the program finishes the current loop and stores the states in a file. I know there’s something called exit\_o…

---

## [Interrupting Task in 0.4 vs 0.5+](https://discourse.julialang.org/t/interrupting-task-in-0-4-vs-0-5/3529)

<div class="topic-metadata">

**Author:** [@jonathanBieler](https://discourse.julialang.org/u/jonathanBieler)\
**Replies:** 0\
**Last updated:** [May 5, 2017, 8:54am UTC](https://discourse.julialang.org/t/interrupting-task-in-0-4-vs-0-5/3529 "2017-05-05T08:54:53Z")

</div>

Interrupting task in 0.4 used to fail gracefully, while in 0.5+ it freezes the REPL in some situations, e.g: 0.4.7 : julia\> t = @schedule begin try remotecall\_fetch(1,sleep,100) cat…

---

## [Catching InterruptException in Embedded Julia](https://discourse.julialang.org/t/catching-interruptexception-in-embedded-julia/38466)

<div class="topic-metadata">

**Author:** [@randy3k](https://discourse.julialang.org/u/randy3k)\
**Replies:** 0\
**Last updated:** [April 30, 2020, 5:30am UTC](https://discourse.julialang.org/t/catching-interruptexception-in-embedded-julia/38466 "2020-04-30T05:30:38Z")

</div>

\#include \<julia.h\> JULIA\_DEFINE\_FAST\_TLS() // only define this once, in an executable (not in a shared library) if you want fast code. int main(int argc, char \*argv\[\]) { jl\_init(); JL\_TRY { jl\_eval\_stri…

---

## [Interrupts in @async code](https://discourse.julialang.org/t/interrupts-in-async-code/95837)

<div class="topic-metadata">

**Author:** [@ettersi](https://discourse.julialang.org/u/ettersi)\
**Replies:** 20\
**Last updated:** [July 19, 2023, 4:16pm UTC](https://discourse.julialang.org/t/interrupts-in-async-code/95837 "2023-07-19T16:16:08Z")

</div>

I’m trying to wrap my head around how Julia handles interrupts in @async code. I have three different scripts that I’m trying to interrupt using ctrl+c, with various degrees of success. Script1: julia\> @async begin …

---

## [Is there any command statement to simulate pressing ctrl-c？](https://discourse.julialang.org/t/is-there-any-command-statement-to-simulate-pressing-ctrl-c/100391)

<div class="topic-metadata">

**Author:** [@13299118606](https://discourse.julialang.org/u/13299118606)\
**Replies:** 3\
**Last updated:** [June 15, 2023, 1:39pm UTC](https://discourse.julialang.org/t/is-there-any-command-statement-to-simulate-pressing-ctrl-c/100391 "2023-06-15T13:39:42Z")

</div>

Is there any command statement to simulate pressing ctrl-c to abort the running program, I am designing a gui abort button, and I want it to press the button to stop the running program. Similar to the “interrupt()” func…

---

## [How to interrupt (not kill) julia from the REPL (again)?](https://discourse.julialang.org/t/how-to-interrupt-not-kill-julia-from-the-repl-again/99753)

<div class="topic-metadata">

**Author:** [@ryofurue](https://discourse.julialang.org/u/ryofurue)\
**Replies:** 6\
**Last updated:** [June 5, 2023, 3:59am UTC](https://discourse.julialang.org/t/how-to-interrupt-not-kill-julia-from-the-repl-again/99753 "2023-06-05T03:59:56Z")

</div>

Instead of adding a question to the old thread 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, h…

---

## [How to interrupt (not kill) julia from the REPL?](https://discourse.julialang.org/t/how-to-interrupt-not-kill-julia-from-the-repl/22565)

<div class="topic-metadata">

**Author:** [@benninkrs](https://discourse.julialang.org/u/benninkrs)\
**Replies:** 25\
**Last updated:** [February 14, 2023, 6:50pm UTC](https://discourse.julialang.org/t/how-to-interrupt-not-kill-julia-from-the-repl/22565 "2023-02-14T18:50:04Z")

</div>

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\_don…

---

## [Is there a macro to make Ctrl+C work in REPL?](https://discourse.julialang.org/t/is-there-a-macro-to-make-ctrl-c-work-in-repl/88794)

<div class="topic-metadata">

**Author:** [@HugoTrentesaux](https://discourse.julialang.org/u/HugoTrentesaux)\
**Replies:** 6\
**Last updated:** [October 16, 2022, 4:58pm UTC](https://discourse.julialang.org/t/is-there-a-macro-to-make-ctrl-c-work-in-repl/88794 "2022-10-16T16:58:47Z")

</div>

This topic shows that Julia REPL can not be interrupted : How to interrupt (not kill) julia from the REPL? Is there a decorator to make a loop able to be interrupted from Ctrl+C in the REPL?

---

## [Setting Timeout and C-C capture](https://discourse.julialang.org/t/setting-timeout-and-c-c-capture/15487)

<div class="topic-metadata">

**Author:** [@iwelch](https://discourse.julialang.org/u/iwelch)\
**Replies:** 2\
**Last updated:** [September 26, 2018, 4:17pm UTC](https://discourse.julialang.org/t/setting-timeout-and-c-c-capture/15487 "2018-09-26T16:17:12Z")

</div>

dear Julia wizards—I want to create julia code segments that recognize (and trap) a control-C; and I want to create julia code that times out. my julia code segments may be trying to obtain something from the host compu…

---

## [Segmentation fault when a try to catch a InterruptException](https://discourse.julialang.org/t/segmentation-fault-when-a-try-to-catch-a-interruptexception/2285)

<div class="topic-metadata">

**Author:** [@Alvaro\_M](https://discourse.julialang.org/u/Alvaro_M)\
**Replies:** 9\
**Last updated:** [February 24, 2017, 10:48pm UTC](https://discourse.julialang.org/t/segmentation-fault-when-a-try-to-catch-a-interruptexception/2285 "2017-02-24T22:48:08Z")

</div>

Hi, I have this code, I’m trying to catch a keyboard interrupt, but what a get it a segmentation fault try for i in 1:10 println(i) sleep(0.5) end catch err if isa(err, InterruptException) exit() …
