4444static bool stdin_received = false ;
4545static bool stdin_sigint = false ;
4646// Global variable to store the original SIGINT handler
47- static struct sigaction originalSigintAction = { 0 } ;
47+ static PyOS_sighandler_t originalSigintAction = NULL ;
4848
4949// Signal handler for SIGINT, only sets a flag to exit the run loop
5050static void handleSigint (int signal) {
@@ -57,10 +57,7 @@ static int wait_for_stdin() {
5757 stdin_sigint = false ;
5858
5959 // Set up a SIGINT handler to interrupt the event loop if ctrl+c comes in too
60- struct sigaction customAction = {0 };
61- customAction.sa_handler = handleSigint;
62- // Set the new handler and store the old one
63- sigaction (SIGINT, &customAction, &originalSigintAction);
60+ originalSigintAction = PyOS_setsig (SIGINT, handleSigint);
6461
6562 // Create an NSFileHandle for standard input
6663 NSFileHandle *stdinHandle = [NSFileHandle fileHandleWithStandardInput ];
@@ -93,7 +90,7 @@ static int wait_for_stdin() {
9390 [[NSNotificationCenter defaultCenter ] removeObserver: stdinHandle];
9491
9592 // Restore the original SIGINT handler upon exiting the function
96- sigaction (SIGINT, & originalSigintAction, NULL );
93+ PyOS_setsig (SIGINT, originalSigintAction);
9794 return 1 ;
9895 }
9996}
0 commit comments