[FIX] bus: fix threads can only be started once

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) <aku@odoo.com>
Signed-off-by: Stockbauer Matthieu (tsm) <tsm@odoo.com>
This commit is contained in:
tsm-odoo
2022-10-12 17:07:40 +02:00
parent ccd45298e4
commit 93fc539bb3
+4 -2
View File
@@ -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)