File size: 643 Bytes
d1e2d14 | 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 | import time
from threading import Lock
from .thread import RecurrentThread
class HZSample:
def __init__(self, interval: float = 1.0):
self.__count = 0
self.__inter = interval if interval > 0.0 else 1.0
self.__lock = Lock()
self.__thread = RecurrentThread(self.__inter, target=self.TimerFunc)
def Start(self):
self.__thread.Start()
def Sample(self):
with self.__lock:
self.__count += 1
def TimerFunc(self):
count = 0
with self.__lock:
count = self.__count
self.__count = 0
print("HZ: {}".format(count/self.__inter))
|