# Is there a macro to make Ctrl+C work in REPL?

**URL:** <https://discourse.julialang.org/t/is-there-a-macro-to-make-ctrl-c-work-in-repl/88794>\
**Category:** New to Julia\
**Tags:** interruptexception\
**Created:** [October 16, 2022, 7:42am UTC](https://discourse.julialang.org/t/is-there-a-macro-to-make-ctrl-c-work-in-repl/88794 "2022-10-16T07:42:06Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![digital\_carver](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/digital_carver/32/33818_2.png) [@digital\_carver](https://discourse.julialang.org/u/digital_carver)\
**Post date:** [October 16, 2022, 10:18am UTC](https://discourse.julialang.org/t/is-there-a-macro-to-make-ctrl-c-work-in-repl/88794/4 "2022-10-16T10:18:27Z")

</div>

Calling `yield()` from within the loop is the generally recommended option for this. It’s not a 100% guarantee as I understand it, but makes it much more likely that the interrupt comes through. See for eg.

> [@What to do when Julia runs away from you? (how to interrupt on C-c?)](https://discourse.julialang.org/t/what-to-do-when-julia-runs-away-from-you-how-to-interrupt-on-c-c/85310):
>
> I’m currently working on a model that somehow get’s in a solving loop that I can’t cancel with Ctrl+C. To prove this I’m printing to the console from within the while loop that is running away. I can see the print statement reporting the ever increasing index to the console, but my keyboard input of Ctrl+C is ignored. Is there another way to interrupt Julia? My only solution at the moment is to kill Julia, but this is not ideal since I need to spend minutes re-compiling the current project.

> [@Interruptible routine: the routine does not receive SIGINT if there is no gap in the loop](https://discourse.julialang.org/t/interruptible-routine-the-routine-does-not-receive-sigint-if-there-is-no-gap-in-the-loop/72746):
>
> Hi all, I am learning to create an Interruptible routine for my camera sensor. My goal is to run an image acquisition routine on a remote process so that the local process can receive command from the user to perform other tasks. I start with this simple example. The routine creates a file, opens it and writes something into it at a certain period as shown below (Please note that the code in the while loop can be anything, I picked writing to a file as an example) @everywhere function worker\_f…

> [@What makes a function interruptible with ctrl+c?](https://discourse.julialang.org/t/what-makes-a-function-interruptible-with-ctrl-c/86625):
>
> Ctrl+c fails to interrupt many functions. What makes a function interruptible?

---

_[View the full topic](https://discourse.julialang.org/t/is-there-a-macro-to-make-ctrl-c-work-in-repl/88794)._
