-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimertest.py
39 lines (34 loc) · 1.08 KB
/
timertest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# import the necessary packages
from threading import Thread
import time
class pingtimer:
def __init__(self, src=0, name="timer"):
# initialize the thread name
self.name = name
self.duration = 0
# initialize the variable used to indicate if the thread should
# be stopped
self.stopped = False
def start(self, duration = 0):
# start the thread to read frames from the video stream
self.duration = duration
t = Thread(target=self.update, name=self.name, args=())
t.daemon = True
t.start()
return self
def update(self):
# keep looping infinitely until the thread is stopped
while True:
# if the thread indicator variable is set, stop the thread
time.sleep(self.duration)
print(1)
if self.stopped:
print('thread exit successfully')
return
def stop(self):
# indicate that the thread should be stopped
self.stopped = True
t = pingtimer()
t.start(duration=2)
time.sleep(10)
t.stop()