Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python input timeout

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
Comment

PREVIOUS NEXT
Code Example
Python :: django dockerfile multistage 
Python :: python convert float to decimal 
Python :: move column in pandas 
Python :: add new keys to a dictionary python 
Python :: python regex 
Python :: python beautiful 
Python :: dataframe KeyError: 
Python :: click ok on alert box selenium webdriver python 
Python :: django save image 
Python :: how to save an image with the same name after editing in python pillow module 
Python :: python webdriver disable logs 
Python :: flask python use specified port 
Python :: tuple length in python 
Python :: type string python 
Python :: Origin in CORS_ORIGIN_WHITELIST is missing scheme or netloc 
Python :: how to iterate over columns of pandas dataframe 
Python :: numpy array input 
Python :: pandas read_csv dtype datetime 
Python :: python copy 
Python :: pandas look for values in column with condition 
Python :: how does urllib.parse.urlsplit work in python 
Python :: linked lists python 
Python :: python upper 
Python :: replace key of dictionary python 
Python :: unittest skip 
Python :: boto3 client python 
Python :: uninstall python linux 
Python :: seaborn histplot modify legend 
Python :: column type pandas as numpy array 
Python :: django set session variable 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =