typedef sig_t signalhandler_type;
typedef sighandler_t signalhandler_type;
void interrupt_init_priv( bool forward );
void interrupt_reset_priv( );
bool interrupt_cont_priv( );
void interrupt_on_priv( );
void interrupt_off_priv( );
static PyObject *InterruptError;
static signalhandler_type original_sigint_handler = 0;
static bool interrupt_has_occurred = false;
static bool interrupt_initialized = false;
static bool interrupt_on = false;
static bool interrupt_forward_sigint = false;
void interrupt_sigint_handler( int sig ) {
interrupt_has_occurred = true;
if ( interrupt_forward_sigint &&
original_sigint_handler != 0 &&
original_sigint_handler != SIG_IGN &&
original_sigint_handler != SIG_DFL &&
original_sigint_handler != SIG_ERR )
(*original_sigint_handler)(sig);
original_sigint_handler = signal(SIGINT,interrupt_sigint_handler);
void interrupt_init_priv( bool forward ) {
if ( interrupt_initialized == false ) {
interrupt_initialized = true;
original_sigint_handler = signal(SIGINT,interrupt_sigint_handler);
interrupt_forward_sigint = forward;
} else if ( interrupt_on ) {
signalhandler_type handler = signal(SIGINT,interrupt_sigint_handler);
if ( handler != interrupt_sigint_handler )
original_sigint_handler = handler;
interrupt_has_occurred = false;
static PyObject *interrupt_init_(PyObject *self, PyObject *args) {
PyArg_ParseTuple( args, "|i", &forward );
interrupt_init_priv(forward != 0 ? true : false);