How do I handle Ctrl-C interrupt in nim?
Asked Answered
D

1

9

If I press Ctrl-C while my program is running it exits and prints SIGINT: Interrupted by Ctrl-C.

How do I ignore the Ctrl-C interrupt in Nim on Linux? Thanks in advance.

Dyandyana answered 15/2, 2019 at 16:18 Comment(0)
D
12

You can control the behaviour of Ctrl+C with setControlCHook:

proc ctrlc() {.noconv.} =
  echo "Ctrl+C fired!"

setControlCHook(ctrlc)

Now CtrlC calls the ctrlc procedure. It's up to that procedure to ignore the SIGINT, or to clean the house and exit with quit.

Decigram answered 16/2, 2019 at 13:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.