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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T20:35:48+00:00 2026-05-12T20:35:48+00:00

For some reason, siginterrupt() only seems to set the behaviour for the first signal

  • 0

For some reason, siginterrupt() only seems to set the behaviour for the first signal received.

In this example program, the first SIGQUIT appears to do nothing, but the second sigquit prints “SIGQUIT Handler” and s.accept() throws an Interrupted system call exception.

from signal import *
from socket import *
import sys

def sigquitHandler(signum, frame):
        print("SIGQUIT Handler")

s = socket()
s.bind(("0.0.0.0", int(sys.argv[1])))
s.listen(5)

signal(SIGQUIT, sigquitHandler)
siginterrupt(SIGQUIT, False)

client, addr = s.accept() # Or any syscall that blocks
client.close()
s.close()

What am i misunderstanding here?


Edit: Here’s something else that i can’t figure out, in this program, a SIGQUIT interrupts the select(). Is that supposed to happen?

from signal import *
import select
import sys

def sigquitHandler(signum, frame):
    print("SIGQUIT Handler")

signal(SIGQUIT, sigquitHandler)
siginterrupt(SIGQUIT, False)

select.select([sys.stdin], [], [])
  • 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-12T20:35:48+00:00Added an answer on May 12, 2026 at 8:35 pm

    Which unix are you using? At the C level, there are different implementations and semantics for signal handling on BSD vs System 5 (SYSV).

    My guess is that you are using SYSV, in which case the signal disposition is reset to SIG_DFL after the signal handler has returned (classical signal handling). On SYSV you need to call signal in the handler to reinstall that handler.

    Python more or less provides BSD style signal handling. So, on a SYSV OS, Python must be managing reinstallation of the signal handler via signal. Now, according to the Python doco for siginterrupt:

    Note that installing a signal handler
    with signal() will reset the restart
    behaviour to interruptible by
    implicitly calling siginterrupt() with
    a true flag value for the given
    signal.

    And there you go – if Python is automatically reinstalling your signal handler (to provide BSD like semantics), it may well be doing so in a way that implicitly calls siginterrupt(1).

    Of course, my guess could be wrong.

    You might be able to fix this by defining sigquitHandler like this:

    def sigquitHandler(signum, frame):
        print("SIGQUIT Handler")
        siginterrupt(SIGQUIT, False)
    

    It depends on when and how Python is restoring the signal disposition.

    EDIT

    Adding siginterrupt(SIGQUIT, False) to the signal handler has no affect.

    EDIT 2

    After some more poking around in the Python2.6 source code it clear that this is not just a SYSV issue. It will affect BSD systems too.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason I never see this done. Is there a reason why not?
For some reason, I can not get this dialog to show up on the
for some reason my server that uses socket.io is not working properly. The program
For some reason my site displays a Cannot display this message error in those
For some reason, when using this code the file it outputs is just called
For some reason this PHP code below will not work, I can not figure
For some reason, the following seems to work perfectly on my ubuntu machine running
for some reason no matter what I do, this is always returning a valid
For some reason this function is doing something weird just in Firefox function fadeOUT_sect(id)
For some reason I can't seem to get this particular web page's contents via

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.