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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:34:53+00:00 2026-05-25T13:34:53+00:00

I am very new to Python, so forgive me if this question is very

  • 0

I am very new to Python, so forgive me if this question is very basic.

I am trying to handle a keyboard interrupt while accepting data from a socket using select module. So, I have a select.select() function call to wait for data from the socket, and then output it to console.

When pressing CTRL_C, it seems that sometimes I get a select.error, and sometimes exceptions.IOError exception. The corresponding error code is 4 for both exceptions.

There is some code that handles KeyboardInterrupt exception deeper in the call stack, so when I get a SIGINT in the function where I accept a socket connection, I just want to re-raise KeyboardInterrupt exception. I also want to catch connection related exceptions.

Would it be safe to check for exception’s error code, and raise KeyboardInterrupt if it is 4? Will this affect my ability to catch connection-related exceptions? Is there a good resource on error codes?

Thanks!

  • 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-25T13:34:54+00:00Added an answer on May 25, 2026 at 1:34 pm

    Use errno.EINTR instead. It is safe.

    >>> import errno
    >>> errno.EINTR
    4
    

    However, this will not tell you which signal interrupted the system call, only that some signal interrupted it.

    From man 2 select:

    EBADF  An  invalid file descriptor was given in one of the sets.  (Per‐
           haps a file descriptor that was already closed, or one on  which
           an error has occurred.)
    
    EINTR  A signal was caught; see signal(7).
    
    EINVAL nfds  is  negative  or  the  value  contained  within timeout is
           invalid.
    
    ENOMEM unable to allocate memory for internal tables.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Apologies if this doesn't make any sense, I'm very new to Python! From testing
I'm very new to Python and have a question. Currently I'm using this to
I am very new with Python and I have just received this message while
I am very new to Python, and trying to figure out how to create
I'm very new to Python (I'm coming from a JAVA background) and I'm wondering
I'm relatively new to the Python world, but this seems very straight forward. Google
I am very new to Python, I need to read numbers from a file
I'm very new to python. two days. trying to get a plot working with
Trying to get a handle on the FTP library in Python. :) Got this
I am very new to python. I am trying to write a program that

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.