From be537a14d2190c790574cf0bf90f583a6c4fec2e Mon Sep 17 00:00:00 2001 From: lucasheld Date: Fri, 7 Apr 2023 20:07:52 +0200 Subject: [PATCH] fix: do not wait for events that have already arrived --- uptime_kuma_api/api.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/uptime_kuma_api/api.py b/uptime_kuma_api/api.py index e13ac01..9d76d0d 100644 --- a/uptime_kuma_api/api.py +++ b/uptime_kuma_api/api.py @@ -451,8 +451,9 @@ class UptimeKumaApi(object): @contextmanager def wait_for_event(self, event: Event) -> None: + # 200 * 0.05 seconds = 10 seconds retries = 200 - event_data_before = deepcopy(self._event_data) + sleep = 0.05 try: yield @@ -460,11 +461,11 @@ class UptimeKumaApi(object): raise else: counter = 0 - while event_data_before[event] == self._event_data[event]: - time.sleep(0.01) + while self._event_data[event] is None: + time.sleep(sleep) counter += 1 if counter >= retries: - print("wait_for_event timeout") + print(f"wait_for_event {event} timeout") break def _get_event_data(self, event) -> Any: