A
A
Andrey2021-12-18 20:08:32
Python
Andrey, 2021-12-18 20:08:32

How to implement a delayed trigger in Python?

Kind. In general, almost complete 0 in python ... Tell me who is not difficult how to implement a trigger with a delay in Python.
Essence of a question:
Is there any variable. It is set to false by default. At some point in time, it may be set to true. But After a certain period of time, the variable should become false again (for example, 1 sec).
And, if at the moment when the variable is assigned true, it is again assigned true, then the delay counter should go to its original position (for example, 1 sec.).
On JS, I would not ask, but here is a python, and I don’t swim in it from the word at all.
Thanks in advance. Preferably either the code or a link to the code. I'll figure it out later.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Kuts, 2021-12-18
@fox_12

at some point in time it can be set to true

give the variable the current time stamp + the delay in seconds
myvar = time.time() + interval
myvar > time.time()   # True, по истечению интервала - станет False

And, if at the moment when the variable is assigned true, it is again assigned true, then the delay counter should go to its original position (for example, 1 sec.).

just assign again
myvar = time.time() + interval

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question