mirror of https://github.com/waku-org/nwaku.git
Fix Ctrl-C quitting (#1416)
This commit is contained in:
parent
b77a4faa55
commit
4b180c89bd
|
@ -687,14 +687,17 @@ when isMainModule:
|
||||||
## Setup shutdown hooks for this process.
|
## Setup shutdown hooks for this process.
|
||||||
## Stop node gracefully on shutdown.
|
## Stop node gracefully on shutdown.
|
||||||
|
|
||||||
|
proc asyncStopper(node: WakuNode) {.async.} =
|
||||||
|
await node.stop()
|
||||||
|
quit(QuitSuccess)
|
||||||
|
|
||||||
# Handle Ctrl-C SIGINT
|
# Handle Ctrl-C SIGINT
|
||||||
proc handleCtrlC() {.noconv.} =
|
proc handleCtrlC() {.noconv.} =
|
||||||
when defined(windows):
|
when defined(windows):
|
||||||
# workaround for https://github.com/nim-lang/Nim/issues/4057
|
# workaround for https://github.com/nim-lang/Nim/issues/4057
|
||||||
setupForeignThreadGc()
|
setupForeignThreadGc()
|
||||||
notice "Shutting down after receiving SIGINT"
|
notice "Shutting down after receiving SIGINT"
|
||||||
waitFor node.stop()
|
asyncSpawn asyncStopper(node)
|
||||||
quit(QuitSuccess)
|
|
||||||
|
|
||||||
setControlCHook(handleCtrlC)
|
setControlCHook(handleCtrlC)
|
||||||
|
|
||||||
|
@ -702,8 +705,7 @@ when isMainModule:
|
||||||
when defined(posix):
|
when defined(posix):
|
||||||
proc handleSigterm(signal: cint) {.noconv.} =
|
proc handleSigterm(signal: cint) {.noconv.} =
|
||||||
notice "Shutting down after receiving SIGTERM"
|
notice "Shutting down after receiving SIGTERM"
|
||||||
waitFor node.stop()
|
asyncSpawn asyncStopper(node)
|
||||||
quit(QuitSuccess)
|
|
||||||
|
|
||||||
c_signal(ansi_c.SIGTERM, handleSigterm)
|
c_signal(ansi_c.SIGTERM, handleSigterm)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue