From 93fc539bb35ee4e939bbbaf8c45b8c9626b30342 Mon Sep 17 00:00:00 2001 From: tsm-odoo Date: Wed, 12 Oct 2022 10:42:26 +0000 Subject: [PATCH] [FIX] bus: fix threads can only be started once MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `ImDispatch` thread uses the `thread.is_alive` method to check whether or not the thread should be started. The issue is that, this method will return `False` after the start method has been called, but before the run method is invoked leading to the RuntimeError: thread can only be started once. This commit fixes this issue by suppressing this error in this case. closes odoo/odoo#103157 X-original-commit: daded0125a4ec2421b9e817aaaa725da2fd96a20 Signed-off-by: Alexandre Kühn (aku) Signed-off-by: Stockbauer Matthieu (tsm) --- addons/bus/models/bus.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/addons/bus/models/bus.py b/addons/bus/models/bus.py index 552e45f4aff..56eac4040c5 100644 --- a/addons/bus/models/bus.py +++ b/addons/bus/models/bus.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +import contextlib import datetime import json import logging @@ -130,8 +131,9 @@ class ImDispatch(threading.Thread): outdated_channels = websocket._channels - channels self._clear_outdated_channels(websocket, outdated_channels) websocket.subscribe(channels, last) - if not self.is_alive(): - self.start() + with contextlib.suppress(RuntimeError): + if not self.is_alive(): + self.start() def unsubscribe(self, websocket): self._clear_outdated_channels(websocket, websocket._channels)