@@ -668,8 +668,27 @@ int main(int argc, const char ** argv) {
668
668
// load the model
669
669
fprintf (stdout, " %s: loading model and initializing main loop\n " , __func__);
670
670
671
+ shutdown_handler = [&](int ) {
672
+ // this should unblock the primary thread;
673
+ terminate (pool);
674
+ return ;
675
+ };
676
+
677
+ #if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
678
+ struct sigaction sigint_action;
679
+ sigint_action.sa_handler = signal_handler;
680
+ sigemptyset (&sigint_action.sa_mask );
681
+ sigint_action.sa_flags = 0 ;
682
+ sigaction (SIGINT, &sigint_action, NULL );
683
+ sigaction (SIGTERM, &sigint_action, NULL );
684
+ #elif defined (_WIN32)
685
+ auto console_ctrl_handler = +[](DWORD ctrl_type) -> BOOL {
686
+ return (ctrl_type == CTRL_C_EVENT) ? (signal_handler (SIGINT), true ) : false ;
687
+ };
688
+ SetConsoleCtrlHandler (reinterpret_cast <PHANDLER_ROUTINE>(console_ctrl_handler), true );
689
+ #endif
690
+
671
691
// It might make sense in the long run to have the primary thread run clean up on the response map and keep the model workers parallel.
672
- // pool = initialize_workers(args, tqueue, rmap);
673
692
pool = new worker_pool;
674
693
for (int i = *args.get_int_param (" --n-parallelism" ); i > 0 ; i--) {
675
694
if (i == 1 ) {
@@ -684,24 +703,9 @@ int main(int argc, const char ** argv) {
684
703
pool->push_back (w);
685
704
}
686
705
}
687
-
688
- #if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
689
- struct sigaction sigint_action;
690
- sigint_action.sa_handler = signal_handler;
691
- sigemptyset (&sigint_action.sa_mask );
692
- sigint_action.sa_flags = 0 ;
693
- sigaction (SIGINT, &sigint_action, NULL );
694
- sigaction (SIGTERM, &sigint_action, NULL );
695
- #elif defined (_WIN32)
696
- auto console_ctrl_handler = +[](DWORD ctrl_type) -> BOOL {
697
- return (ctrl_type == CTRL_C_EVENT) ? (signal_handler (SIGINT), true ) : false ;
698
- };
699
- SetConsoleCtrlHandler (reinterpret_cast <PHANDLER_ROUTINE>(console_ctrl_handler), true );
700
- #endif
701
-
702
- clean_up ();
706
+ fprintf (stdout, " HTTP server listening on hostname: %s and port: %d, is shutting down.\n " , args.get_string_param (" --host" ).c_str (), *args.get_int_param (" --port" ));
707
+ svr->stop ();
703
708
t.join ();
704
- terminate (pool);
705
709
rmap->cleanup_thread ->join ();
706
710
707
711
return 0 ;
0 commit comments