detect closed eyes after it closed 3 seconds
<p>I want to detect closed eyes after it closed 3 seconds using openCV in python . But when I used time.sleep(1) to count time, the entire program is stopped .
But the program must be run continuously to dectect close eyes. 
I think that can be used thread in python</p>

<pre><code> def get_frame(self):

    success, image = self.video.read()
    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    faces = faceCascade.detectMultiScale(
        gray,
        scaleFactor=1.3,
        minNeighbors=5,
        minSize=(30, 30),
        flags=cv2.cv.CV_HAAR_SCALE_IMAGE
    )



    while True:
        for (x, y, w, h) in faces:
            cv2.rectangle(image, (x, y), (x + w, y + h), (255, 255, 0), 2)

            roi_gray = gray[y:y+h, x:x+w]
            roi_color = image[y:y+h, x:x+w]
            eyes = eyesCascade.detectMultiScale(roi_gray)
            if eyes is not():
                for (ex,ey,ew,eh) in eyes:
                    cv2.rectangle(roi_color,(ex -10 ,ey - 10),(ex+ew + 10,ey+eh + 10),(0,255,0),2)
                    twoeyes = twoeyesCascade.detectMultiScale(roi_gray)
                    checkyeys = 0
                    if twoeyes is not():
                        for (exx,eyy,eww,ehh) in twoeyes:
                            checkyeys = 0
                            led.write(1)
                            cv2.rectangle(roi_color,(exx-5 ,eyy -5  ),(exx+eww -5,eyy+ehh -5 ),(0,0, 255),2)
                    else:
                        #when eyes close
                        print "------------------------------------"
                        for i in xrange(10):
                            time.sleep(1)
                            if(i % 3 == 0){
                                #eyes close in 3 seconds
                                print "Warning"
                            }
                            print i
        ret, jpeg = cv2.imencode('.jpg', image)
        self.string = jpeg.tostring()
        self._image = image
        return jpeg.tostring()
</code></pre>

<p>Thank for helping !!! </p>

<p>Try to change </p>

<pre><code>if(i % 3 == 0){
   #eyes close in 3 seconds
   print "Warning"
}
</code></pre>

<p>to</p>

<pre><code>if i % 3 == 0:
   #eyes close in 3 seconds
   print "Warning"
</code></pre>

python opencv