How to make a timer in Python 3?

0

I have to make a timer that counts x seconds, but that does not stay in loop waiting for the time to pass, instead it must count the time and generate an event when closing the count of the pre-defined time. I need to know if there is a module in Python 3 that can perform this function and that has a start and a reset in the count?     

asked by anonymous 13.06.2018 / 22:15

1 answer

2

As I mentioned in the answer below

Python input function timeout

You can use the signal module on Unix systems to call a function after a certain time, without blocking the execution of the main program.

import signal

def evento(*args):
    print("Evento disparado")

signal.signal(signal.SIGALRM, evento)
signal.alarm(5)

resposta = input('Por favor, aguarde 5 segundos...')

See working at Repl.it | GitHub GIST

For Windows, you can adapt the solution I presented in the other response in the same way.

    
13.06.2018 / 22:29