Update server.cpp
For correct processing ctrl+c signal
This commit is contained in:
parent
c026ba3c23
commit
1edd618084
1 changed files with 18 additions and 17 deletions
|
@ -3388,6 +3388,24 @@ int main(int argc, char ** argv) {
|
||||||
// struct that contains llama context and inference
|
// struct that contains llama context and inference
|
||||||
server_context ctx_server;
|
server_context ctx_server;
|
||||||
|
|
||||||
|
shutdown_handler = [&](int) {
|
||||||
|
ctx_server.queue_tasks.terminate();
|
||||||
|
};
|
||||||
|
|
||||||
|
#if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
|
||||||
|
struct sigaction sigint_action;
|
||||||
|
sigint_action.sa_handler = signal_handler;
|
||||||
|
sigemptyset (&sigint_action.sa_mask);
|
||||||
|
sigint_action.sa_flags = 0;
|
||||||
|
sigaction(SIGINT, &sigint_action, NULL);
|
||||||
|
sigaction(SIGTERM, &sigint_action, NULL);
|
||||||
|
#elif defined (_WIN32)
|
||||||
|
auto console_ctrl_handler = +[](DWORD ctrl_type) -> BOOL {
|
||||||
|
return (ctrl_type == CTRL_C_EVENT) ? (signal_handler(SIGINT), true) : false;
|
||||||
|
};
|
||||||
|
SetConsoleCtrlHandler(reinterpret_cast<PHANDLER_ROUTINE>(console_ctrl_handler), true);
|
||||||
|
#endif
|
||||||
|
|
||||||
llama_backend_init();
|
llama_backend_init();
|
||||||
llama_numa_init(params.numa);
|
llama_numa_init(params.numa);
|
||||||
|
|
||||||
|
@ -4484,27 +4502,10 @@ int main(int argc, char ** argv) {
|
||||||
ctx_server.update_slots();
|
ctx_server.update_slots();
|
||||||
});
|
});
|
||||||
|
|
||||||
shutdown_handler = [&](int) {
|
|
||||||
ctx_server.queue_tasks.terminate();
|
|
||||||
};
|
|
||||||
|
|
||||||
LOG_INF("%s: server is listening on http://%s:%d - starting the main loop\n", __func__, params.hostname.c_str(), params.port);
|
LOG_INF("%s: server is listening on http://%s:%d - starting the main loop\n", __func__, params.hostname.c_str(), params.port);
|
||||||
|
|
||||||
ctx_server.queue_tasks.start_loop();
|
ctx_server.queue_tasks.start_loop();
|
||||||
|
|
||||||
#if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
|
|
||||||
struct sigaction sigint_action;
|
|
||||||
sigint_action.sa_handler = signal_handler;
|
|
||||||
sigemptyset (&sigint_action.sa_mask);
|
|
||||||
sigint_action.sa_flags = 0;
|
|
||||||
sigaction(SIGINT, &sigint_action, NULL);
|
|
||||||
sigaction(SIGTERM, &sigint_action, NULL);
|
|
||||||
#elif defined (_WIN32)
|
|
||||||
auto console_ctrl_handler = +[](DWORD ctrl_type) -> BOOL {
|
|
||||||
return (ctrl_type == CTRL_C_EVENT) ? (signal_handler(SIGINT), true) : false;
|
|
||||||
};
|
|
||||||
SetConsoleCtrlHandler(reinterpret_cast<PHANDLER_ROUTINE>(console_ctrl_handler), true);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
clean_up();
|
clean_up();
|
||||||
t.join();
|
t.join();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue