Skip to content

Commit fc6c781

Browse files
ngxsoncebtenzzre
authored andcommitted
server : hit Ctrl+C twice to exit (ggml-org#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 <[email protected]> --------- Co-authored-by: Jared Van Bortel <[email protected]>
1 parent 70ddbcc commit fc6c781

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

examples/server/server.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2772,7 +2772,16 @@ static void append_to_generated_text_from_generated_token_probs(llama_server_con
27722772
}
27732773

27742774
std::function<void(int)> shutdown_handler;
2775-
inline void signal_handler(int signal) { shutdown_handler(signal); }
2775+
std::atomic_flag is_terminating = ATOMIC_FLAG_INIT;
2776+
inline void signal_handler(int signal) {
2777+
if (is_terminating.test_and_set()) {
2778+
// in case it hangs, we can force terminate the server by hitting Ctrl+C twice
2779+
// this is for better developer experience, we can remove when the server is stable enough
2780+
fprintf(stderr, "Received second interrupt, terminating immediately.\n");
2781+
exit(1);
2782+
}
2783+
shutdown_handler(signal);
2784+
}
27762785

27772786
int main(int argc, char **argv)
27782787
{

0 commit comments

Comments
 (0)