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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:37:45+00:00 2026-06-15T11:37:45+00:00

When I press Ctrl-C, the following code terminates immediately. However, it seems that the

  • 0

When I press Ctrl-C, the following code terminates immediately.

However, it seems that the loop should exit after a 10 second delay – because it is not checking the status of keep_going until we reach the top of the loop. Why is this code exiting the loop immediately?

How would I make sure that the loop finishes execution before exiting?

import signal
import time

keep_going = True

def signal_handler(signal, frame):
    global keep_going
    print 'quitting!'
    keep_going = False

signal.signal(signal.SIGINT, signal_handler) 

while keep_going:
    print 'looping...'
    time.sleep(10)
    print 'bye!'
  • 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-06-15T11:37:48+00:00Added an answer on June 15, 2026 at 11:37 am

    From Python docs:

    The actual suspension time may be less than that requested because any caught signal will terminate the sleep() following execution of that signal’s catching routine.

    I.e. the loop does finish its execution (as you can see from the "bye" being output after the signal handler’s "quitting!"), it’s just sleep that is cut short.

    If you had something more substantial than sleep, I believe you’d see what you originally wanted.

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

Sidebar

Related Questions

When I run the first code and press ctrl-c immediately there will be no
I'm using the following code to catch when people press Ctrl + Shift +
see by writting some code here we select that code & press ctrl +
When I tried press the CTRL+D+E keys combination, I typed a wrong combination that
In Netbeans, if I press Ctrl-space in one of these conditions: after a field
If I close the browser tab and press Ctrl + Z to exit the
Whenever I press Ctrl + S in eclipse to save source code I want
My app is forced to close after I press Ctrl-F11 to rotate screen. Here's
I have the following script: tail -f nohup.out echo 5 When I press Ctrl
When I press CTRL + Space the auto completing not working. It doesn't show

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.