Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5959401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:40:46+00:00 2026-05-22T18:40:46+00:00

I currently need to provide multiple keyboard interrupts for a program. Is there an

  • 0

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()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T18:40:47+00:00Added an answer on May 22, 2026 at 6:40 pm

    The Ctrl+\ that has been mentioned is interpreted by your terminal software, and the key binding is configured through stty. Unless you have some way of customizing your terminal software you’ll only be able to use the few signals that are already built in.

    Depending on how much functionality you need or how far you want to take it, another option is to write your own simple “process execution terminal”. This would be a script that executes an app for you and places your terminal in raw mode so that it can process keystrokes which perform custom actions.

    Below is an oversimplified example showing what I mean. You could also do something similar via curses or urwid if you like.

    To handle process output you’d need to capture the stdout/stderr of and display it nicely to the screen, using ANSI escape sequences if you are manipulating the terminal manually, or using an urwid widget to display the output in a scrolling window, etc. The same idea would also extend to other GUI systems (wx, tkinter, etc) but terminal control was mentioned.

    Here is term.py which implements a basic raw terminal interpreter:

    import os, signal, subprocess, sys, tty, termios
    
    sigmap = {
        '\x15': signal.SIGUSR1,     # ctrl-u
        '\x1c': signal.SIGQUIT,     # ctrl-\
        '\x08': signal.SIGHUP,      # ctrl-h
        '\x09': signal.SIGINT,      # ctrl-i
        }
    # setup tty
    fd = sys.stdin.fileno()
    old_tc = termios.tcgetattr(fd)
    tty.setraw(fd)
    # spawn command as a child proc
    cmd = sys.argv[1:]
    proc = subprocess.Popen(cmd)
    while 1:
        try:
            ch = sys.stdin.read(1)
            # example of ansi escape to move cursor down and to column 0
            print '\033[1Eyou entered', repr(ch)
            if ch == 'q':
                break
            signum = sigmap.get(ch)
            if signum:
                os.kill(proc.pid, signum)
        finally:
            pass
    termios.tcsetattr(fd, termios.TCSANOW, old_tc)
    sys.exit()
    

    Here is a simple target.py script to spin and print the signals it receives:

    import signal, sys, time
    
    def handler(num, _):
        print 'got:', sigmap.get(num, '<other>')
        if num == signal.SIGINT:
            sys.exit(1)
        return 1
    
    signames = ['SIGINT','SIGHUP','SIGQUIT','SIGUSR1']
    sigmap = dict((getattr(signal, k), k) for k in signames)
    for name in signames:
        signal.signal(getattr(signal, name), handler)
    while 1:
        time.sleep(1)
    

    Usage example:

    % python term.py python target.py
    you entered 'h'
    you entered 'i'
    you entered '\x1c'
                      got: SIGQUIT
    you entered '\x15'
                      got: SIGUSR1
    you entered '\x08'
                      got: SIGHUP
    you entered '\t'
                    got: SIGINT
    you entered 'q'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to upgrade my current version of DNN this week. I am currently
I need to grab the folder name of a currently executing batch file. I
I need to keep an NSPathControl updated with the currently selected path in an
I need to update a field (which is currently empty) based on a match
I'm currently working on a pet project and need to do C++ development on
We are currently using SharpZipLib but since it uses the GPL we need to
Currently I am evaluating number of web service frameworks in Java. I need web
I am currently developing a site and have a need for a javascript-based carousel/slider
I am currently working on a project where users need to be able to
I'm currently working on a Silverlight app and need to convert XML data into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.