Multi-threading with a simple timer?

Gregory Ewing greg.ewing at
Tue Jul 3 02:12:57 EDT 2018

David D wrote:
> Is there a SIMPLE method that I can have a TIMER count down at a user input
> prompt - if the user doesn't enter information within a 15 second period, it
> times out.

import signal, sys

def timeout(*args):
     print("Too late!")

signal.signal(signal.SIGALRM, timeout)
signal.setitimer(signal.ITIMER_REAL, 15)
data = input("Enter something: ")
print("You entered: ", data)


More information about the Python-list mailing list