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 6622967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:28:29+00:00 2026-05-25T21:28:29+00:00

This morning I decided to handle keyboard interrupt in my server program and exit

  • 0

This morning I decided to handle keyboard interrupt in my server program and exit gracefully. I know how to do it, but my finicky self didn’t find it graceful enough that ^C still gets printed. How do I avoid ^C getting printed?

import sys
from time import sleep
try:
  sleep(5)
except KeyboardInterrupt, ke:
  sys.exit(0)

Press Ctrl+C to get out of above program and see ^C getting printed. Is there some sys.stdout or sys.stdin magic I can use?

  • 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-25T21:28:30+00:00Added an answer on May 25, 2026 at 9:28 pm

    This will do the trick, at least in Linux

    #! /usr/bin/env python
    import sys
    import termios
    import copy
    from time import sleep
    
    fd = sys.stdin.fileno()
    old = termios.tcgetattr(fd)
    new = copy.deepcopy(old)
    new[3] = new[3] & ~termios.ECHO
    
    try:
      termios.tcsetattr(fd, termios.TCSADRAIN, new)
      sleep(5)
    except KeyboardInterrupt, ke:
      pass
    finally:
      termios.tcsetattr(fd, termios.TCSADRAIN, old)
      sys.exit(0)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This morning I finally made my mind and decided to ask you for help.
all. I decided to hack iswitchb this morning, and found a confusing thing. Usually,when
This morning my notebook decided to give me a nice present: Killed mount: mounting
I've been researching this all morning and have decided that as a last-ditch effort,
Recently I published my new app, and this morning I decided to make a
I really need to be somewhere else this morning. So, I have decided to
This morning i rode chapters 39,40 and 41 of the JEE6 tutorial. But i
I've spent this morning searching google for this, but I just can't get what
I thought of a neat hack this morning, probably not original, but I haven't
I got a big problem this morning. My SQL Server had a HUGE bug

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.