Multi-threading with a simple timer?

Michael Vilain michael.vilain at gmail.com
Tue Jul 3 09:06:40 EDT 2018


Won't this code send a signal *regardless* of the user input to the process within 15 seconds. I don't see how it's tied to terminal input.

From what I can tell, you need to create your own version of input with a timeout option.  This doesn't do that.
--
Michael Vilain
650-322-6755

> 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




More information about the Python-list mailing list