OSDir


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[no subject]


> On 02-Jul-2018, at 11:12 PM ?, Gregory Ewing <greg.ewing at canterbury.ac.nz> wrote:
> 
> 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!")
>    sys.exit(0)
> 
> signal.signal(signal.SIGALRM, timeout)
> signal.setitimer(signal.ITIMER_REAL, 15)
> data = input("Enter something: ")
> print("You entered: ", data)
> 
> -- 
> Greg
> -- 
> https://mail.python.org/mailman/listinfo/python-list