From a2ed3d3d5bdb6025a1ba14ad557a115a86413e65 Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Wed, 6 Sep 2017 15:26:49 +0200 Subject: [PATCH] [FIX] bus: compatibility with Odoo's PAAS external long polling handler Only start the bus events dispatcher when needed (lazy starting). On Odoo PAAS it's never started because the platform has its own event dispatcher. --- addons/bus/models/bus.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/addons/bus/models/bus.py b/addons/bus/models/bus.py index 8795a6047c8..8b04b450a86 100644 --- a/addons/bus/models/bus.py +++ b/addons/bus/models/bus.py @@ -108,6 +108,7 @@ class ImBus(models.Model): class ImDispatch(object): def __init__(self): self.channels = {} + self.started = False def poll(self, dbname, channels, last, options=None, timeout=TIMEOUT): if options is None: @@ -129,6 +130,10 @@ class ImDispatch(object): notifications = env['bus.bus'].poll(channels, last, options) # or wait for future ones if not notifications: + if not self.started: + # Lazy start of events listener + self.start() + event = self.Event() for channel in channels: self.channels.setdefault(hashable(channel), []).append(event) @@ -178,15 +183,16 @@ class ImDispatch(object): import gevent self.Event = gevent.event.Event gevent.spawn(self.run) - elif odoo.multi_process: - # disabled in prefork mode - return else: # threaded mode self.Event = threading.Event t = threading.Thread(name="%s.Bus" % __name__, target=self.run) t.daemon = True t.start() + self.started = True return self -dispatch = ImDispatch().start() +dispatch = None +if not odoo.multi_process or odoo.evented: + # We only use the event dispatcher in threaded and gevent mode + dispatch = ImDispatch()