I am currently writing a program that uses openCV with a haar cascade for eyes. I need it to run some code if eyes are not detected for a few seconds, and I can't figure out how to use the time library to check the time. Here is an example of something I have tried.

```
if len(eyes) == 0:
    if noEyeTime - startTime > 2:
        print("closed for more than 2 seconds")
        time.sleep(2)
        startTime = time.time()
    noEyeTime = time.time()
# The variables are declared outside of the while loop

```

This is the check that I've written (it's inside a while True loop), and I've tried moving around the variable updates but I can't figure out how to check if eyes have not been detected for x amount of time.

I also read this post:
[Python if condition true for x amount of time](https://stackoverflow.com/questions/51263299/python-if-condition-true-for-x-amount-of-time)

But the solution doesn't work for me because the program still needs to be running, so time.sleep() is not an option.

Thanks in advance.