I am looking for knowledge.
I am currently working on a program which, if no one is detected by my sensor for 30 seconds, launches a video. I am currently using time.time()
but the concern is that despite trying to reset, the timer continues and does not reset to 0 once the video is finished.
So I tried some new research and I came across a topic about time.clock()
and I ended up with this: Python's time.clock() vs time.time()
But I'm not sure I fully understand the role of timeit
, time.process_time()
or time.perf_counter()
, is there a possibility to use these in the way I want? Or is it only used to calculate the execution time of a code as found in several examples?
Precision:
When I reach 30 seconds, I enter the if to launch the video, the launch video, followed by a time.sleep()
. The timer does not pause and continues while the video is running. Once the video is finished I try to reset the timer, also once the 50 seconds are reached but I can't do it, I probably don't reset what I need. The timer therefore never stops and my other functions which require a timer (if timer> 7
) are launched directly since the condition is fulfilled (whereas they should start again from 0 when entering the other functions)
PS: When a video is running, the other videos are not superimposed on it, they kindly wait their turn
while True:
if ...:
try:
if(200 <= DD): # If we are more than 200 cm away
# We count the number of seconds between the last checkpoint and now
face_walking_apparition_time = time.time() - walking_timer # (t+3) - t = 3, it's how u calculate timer
# Then we check if a face has appeared for more than 30 seconds:
if face_walking_apparition_time > 30: # If the block is detected more than 30 seconds
# Display video
time.sleep(25)
face_motionless_apparition_time = 0 # I try to reset here
face_walking_apparition_time = 0 # I try to reset here
if face_walking_apparition_time >= 50: # After 20 seconds of video, reset
face_walking_apparition_time = 0 #I try to reset here
face_motionless_apparition_time = 0 # I try to reset here
elif (50 < DD) and (DD < 200):
# As we don't see no face, we have to reset our checkpoint to "now"
face_motionless_apparition_time = 0 # I try to reset here
face_walking_apparition_time = 0 # I try to reset here
PS: I'm new to python so my code might be horrible to read