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

The Archive Base Latest Questions

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

How would you prompt the user for some input but timing out after N

  • 0

How would you prompt the user for some input but timing out after N seconds?

Google is pointing to a mail thread about it at http://mail.python.org/pipermail/python-list/2006-January/533215.html but it seems not to work. The statement in which the timeout happens, no matter whether it is a sys.input.readline or timer.sleep(), I always get:

<type 'exceptions.TypeError'>: [raw_]input expected at most 1 arguments, got 2

which somehow the except fails to catch.

  • 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-12T09:48:24+00:00Added an answer on May 12, 2026 at 9:48 am

    The example you have linked to is wrong and the exception is actually occuring when calling alarm handler instead of when read blocks. Better try this:

    import signal
    TIMEOUT = 5 # number of seconds your want for timeout
    
    def interrupted(signum, frame):
        "called when read times out"
        print 'interrupted!'
    signal.signal(signal.SIGALRM, interrupted)
    
    def input():
        try:
                print 'You have 5 seconds to type in your stuff...'
                foo = raw_input()
                return foo
        except:
                # timeout
                return
    
    # set alarm
    signal.alarm(TIMEOUT)
    s = input()
    # disable the alarm after success
    signal.alarm(0)
    print 'You typed', s
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to prompt the user for some input on a webpage. I
I have a large webform, and would like to prompt the user to login
I would like to offer a database connection prompt to the user. I can
I am making an application where the user is prompt at some point to
I downloaded some scripts in both python and bash that prompt the user for
I am validating input on a form and attempting to prompt the user of
I've created a login submit form in HTML but for some reason user/password autocompletion
I have a batch script that prompts a user for some input then outputs
For example; with the old command prompt it would be: cmd.exe /k mybatchfile.bat
Would a C++ CLI compiler be able to compile some large sets of C++

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.