summaryrefslogtreecommitdiff
path: root/examples/server/server.cpp
diff options
context:
space:
mode:
authorXuan Son Nguyen <thichthat@gmail.com>2024-02-28 09:55:37 +0100
committerGitHub <noreply@github.com>2024-02-28 10:55:37 +0200
commita693bea1e6762a17b78b6ddf4611e54136941ea2 (patch)
treed39d715d2f113f060975e06d5d8a5a4429f34a00 /examples/server/server.cpp
parentadcb12a9bad87bc96f2f158c95892b3d04aa7ffb (diff)
server : hit Ctrl+C twice to exit (#5734)
* server: twice ctrl+C to exit * std::atomic_flag * sigint: message * sigint: stderr * Update examples/server/server.cpp Co-authored-by: Jared Van Bortel <cebtenzzre@gmail.com> --------- Co-authored-by: Jared Van Bortel <cebtenzzre@gmail.com>
Diffstat (limited to 'examples/server/server.cpp')
-rw-r--r--examples/server/server.cpp11
1 files changed, 10 insertions, 1 deletions
diff --git a/examples/server/server.cpp b/examples/server/server.cpp
index 6b3ee531..080fa9bd 100644
--- a/examples/server/server.cpp
+++ b/examples/server/server.cpp
@@ -2772,7 +2772,16 @@ static void append_to_generated_text_from_generated_token_probs(llama_server_con
}
std::function<void(int)> shutdown_handler;
-inline void signal_handler(int signal) { shutdown_handler(signal); }
+std::atomic_flag is_terminating = ATOMIC_FLAG_INIT;
+inline void signal_handler(int signal) {
+ if (is_terminating.test_and_set()) {
+ // in case it hangs, we can force terminate the server by hitting Ctrl+C twice
+ // this is for better developer experience, we can remove when the server is stable enough
+ fprintf(stderr, "Received second interrupt, terminating immediately.\n");
+ exit(1);
+ }
+ shutdown_handler(signal);
+}
int main(int argc, char **argv)
{