I'm building my first timer in Python and looking into time module. This is what I want:
Inside while loop, when the if condition "A" is true for the first time, start timer
When 10 seconds has passed, trigger an event
When 30 seconds has passed, clear timer so that it's ready to start again when if condition "A" is true
I feel like I have all the building blocks but still cannot get my head around for starting the 10 second timer. In pseudocode, I want this:
if current_time - the_time_from_first_if_statement_match > 10:
do something
This is what I have now. Any help appreciated!
def main():
start_time = time.time()
time_limit = 10
while True:
current_time = time.time() #keeps updating
matchresult = video_process.match
if matchresult == True:
elapsed_time = current_time - start_time #can be anything like 14 or 100 at this point, I'd just want a 10 sec timer
if elapsed_time > time_limit:
print("do something")
matchresultis not defined.matchresultis true) and keeps doing so forever. How are you trying to solve Step #3?elapsed_timecan be 100 or 1000 whenmatchresultis true for the first time (it's an interactive piece that waits for people to come and interact). That means thatelapsed_timeis immediately more thantime_limitin that case and no 10 sec timer is created. Step 3 I haven't tried yet before solving my first problem!