From 949baac5b01efd29bbd6664513597604b0bf0d9c Mon Sep 17 00:00:00 2001 From: clavay Date: Wed, 3 May 2023 14:22:49 +0200 Subject: [PATCH] force channel layer to be empty since the version 4 of channel redis version, the channel layer is not empty after the first read we read it again to empty it maybe it is related to https://github.com/django/channels_redis/issues/348 or to https://github.com/django/channels_redis/issues/366 --- pyscada/utils/scheduler.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pyscada/utils/scheduler.py b/pyscada/utils/scheduler.py index ca54789f..4f7aec18 100644 --- a/pyscada/utils/scheduler.py +++ b/pyscada/utils/scheduler.py @@ -845,7 +845,12 @@ async def waiting_action_receiver(self, dt, message): self.dwt_received = True if 'ProcessSignal' in a: logger.debug("Received ProcessSignal %s on channel_layer for %s" % (a['ProcessSignal'], self.label)) - #logger.debug(a) + + # BUG : need to empty the channel_layer, if not the channel layer keep the message for each run loop + try: + await wait_for(self.channel_layer.receive(message), timeout=0.01) + except asyncioTimeoutError: + pass else: #logger.debug("sleep for %s - %s" % (self.process_id, dt)) sleep(dt)