Alex Rivera | Logout

Python: Built-in Keyboard Signal/Interrupts

Asked 2011-03-29T16:01:57.757
11

I currently need to provide multiple keyboard interrupts for a program. Is there an easy way to do this with the signal class? I currently use the SIGINT/Ctrl+C but I can't find any other keyboard mappings.

Would be nice to have more than 2 signals. How can I either define more signals or is there a better way to capture an "interrupt from a user"?

Here is a highlevel view of the current code:

 def shutdown(signal, frame):
       if(signal==2): #sigint
          print 'do something'
       elif signal==XX:
          print 'do something else'
       # continued...

 signal.signal(signal.SIGINT, shutdown)
 signal.signal(signal.SOMEOTHERTYPE, shutdown)


 print 'start'
 t = Thread(target=run)
 t.setDaemon(True)
 t.start()

 print 'Done, press ctrl c, or ctrl ? '
 signal.pause()
Edit
Report

1 Answer

7

On Linux systems, Ctrl+\ will generate a signal.SIGQUIT signal.

answered 2011-03-29T16:29:21.703

Your Answer