ABlockMonitor parametres

This commit is contained in:
AF 2022-11-08 01:32:43 +00:00
parent 782a934af9
commit 1422f0a762

View File

@ -55,19 +55,24 @@ class ABlockMonitor:
__task: asyncio.Future __task: asyncio.Future
__max: float __max: float
def __init__(self, threshold=0.0) -> None: def __init__(self, *, threshold=0.0, delta=10.0, interval=0.0) -> None:
self.__max = threshold self.__max = threshold
self.delta = delta
self.interval = interval
async def _monitor(self): async def _monitor(self):
while True: while True:
delta = 10 delta = self.delta
t = time.time() t = time.time()
await asyncio.sleep(delta) await asyncio.sleep(delta)
spent = time.time() - t spent = time.time() - t
delay = spent - delta delay = spent - delta
if delay > self.__max: if delay > self.__max:
self.__max = delay self.__max = delay
print(f'block monitor reached new peak delay {delay:.3f}') print(f'block monitor reached new peak delay {delay:.4f}')
interval = self.interval
if interval > 0:
await asyncio.sleep(interval)
async def __aenter__(self): async def __aenter__(self):
self.__task = asyncio.get_running_loop().create_task(self._monitor()) self.__task = asyncio.get_running_loop().create_task(self._monitor())