File tree Expand file tree Collapse file tree 3 files changed +17
-1
lines changed Expand file tree Collapse file tree 3 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -681,7 +681,14 @@ static void setup_cysignals_handlers(void)
681
681
sigprocmask (SIG_SETMASK , & default_sigmask , & sigmask_with_sigint );
682
682
#endif
683
683
684
- /* Install signal handlers */
684
+ /* Install signal handlers. We need a separate C-level interrupt handler
685
+ * apart from the Python-level interrupt handler because Python-level
686
+ * interrupt handler will not be called inside Cython code.
687
+ * See init_cysignals and python_check_interrupt for an explanation.
688
+ * A downside is the C-level interrupt handler will be overwritten
689
+ * when signal(SIGINT, getsignal(SIGINT)) is executed, in that case
690
+ * init_cysignals() need to be called again.
691
+ */
685
692
/* Handlers for interrupt-like signals */
686
693
sa .sa_handler = cysigs_interrupt_handler ;
687
694
sa .sa_flags = 0 ;
Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ cdef extern from "struct_signals.h":
26
26
27
27
ctypedef struct cysigs_t:
28
28
cy_atomic_int sig_on_count
29
+ cy_atomic_int interrupt_received
29
30
cy_atomic_int block_sigint
30
31
const char * s
31
32
PyObject* exc_value
Original file line number Diff line number Diff line change @@ -353,6 +353,14 @@ def python_check_interrupt(sig, frame):
353
353
``implementation.c``.
354
354
"""
355
355
sig_check()
356
+ if cysigs.exc_value:
357
+ return
358
+ # If this line is reached, a possibility is that something called
359
+ # signal(SIGINT, getsignal(SIGINT)), which cause cysigs_interrupt_handler
360
+ # to not be called. We reinstall the C-level signal handler.
361
+ init_cysignals()
362
+ cysigs.interrupt_received = sig
363
+ sig_check()
356
364
357
365
358
366
cdef void verify_exc_value() noexcept:
You can’t perform that action at this time.
0 commit comments