From a1dd4f11b6623bd92673492b4f0d6b0e6c392365 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 18 Feb 2024 15:15:31 -0600 Subject: [PATCH 1/2] Refactor AsyncioTelemetryManager to avoid creating a task every second --- pubnub/pubnub_asyncio.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/pubnub/pubnub_asyncio.py b/pubnub/pubnub_asyncio.py index d47eb40c..d9912f3a 100644 --- a/pubnub/pubnub_asyncio.py +++ b/pubnub/pubnub_asyncio.py @@ -794,14 +794,18 @@ async def wait_for_presence_on(self, *channel_names): class AsyncioTelemetryManager(TelemetryManager): def __init__(self): TelemetryManager.__init__(self) - self._timer = AsyncioPeriodicCallback( - self._start_clean_up_timer, - self.CLEAN_UP_INTERVAL * self.CLEAN_UP_INTERVAL_MULTIPLIER, - asyncio.get_event_loop()) - self._timer.start() + self.loop = asyncio.get_event_loop() + self._schedule_next_cleanup() - async def _start_clean_up_timer(self): + def _schedule_next_cleanup(self): + self._timer = self.loop.call_later( + self.CLEAN_UP_INTERVAL * self.CLEAN_UP_INTERVAL_MULTIPLIER / 1000, + self._start_clean_up_timer + ) + + def _start_clean_up_timer(self): self.clean_up_telemetry_data() + self._schedule_next_cleanup() def _stop_clean_up_timer(self): - self._timer.stop() + self._timer.cancel() From 618bd68acdcac6ec1982e23ef7f501b5d850f89b Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 18 Feb 2024 15:19:11 -0600 Subject: [PATCH 2/2] naming --- pubnub/pubnub_asyncio.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pubnub/pubnub_asyncio.py b/pubnub/pubnub_asyncio.py index d9912f3a..14c83eec 100644 --- a/pubnub/pubnub_asyncio.py +++ b/pubnub/pubnub_asyncio.py @@ -800,10 +800,10 @@ def __init__(self): def _schedule_next_cleanup(self): self._timer = self.loop.call_later( self.CLEAN_UP_INTERVAL * self.CLEAN_UP_INTERVAL_MULTIPLIER / 1000, - self._start_clean_up_timer + self._clean_up_schedule_next ) - def _start_clean_up_timer(self): + def _clean_up_schedule_next(self): self.clean_up_telemetry_data() self._schedule_next_cleanup()