connect SIGINT to custom interrupt handler

Christoph Scheingraber chris at spam.org
Sun May 15 05:44:04 EDT 2011


Hi,

I am trying to connect SIGINT (^c) to a custom interrupt handler like
this (no threading, just straightforward): 



if __name__ == "__main__":
quit = False
def interrupt_handler(signal, frame):
    global quit
    if not quit:
        print "blabla, i'll finish my task and quit kind of message"
        print "Press ^C again to interrupt immediately."
    else:
        sys.exit(2)
    quit = True
signal.signal(signal.SIGINT, interrupt_handler)
# main will use the quit flag to determine if it should quit before next
# task
status = main()


This worked fine in some rare lucky cases, but most of the times, the
module I am using (my university's seismology project) catches the SIGINT
and quits:

select.error: (4, 'Interrupted system call')

How can I prevent the imported module's function from catching the
interrupt signal?


Thanks to anyone that takes the time to help me...

Chris

-- 
Chris Scheingraber - www.scheingraber.net



More information about the Python-list mailing list