From 6188a61de3db35ab4944343acd3ccab61c9eeebe Mon Sep 17 00:00:00 2001 From: Gert Pellin Date: Wed, 3 Apr 2019 13:35:46 +0000 Subject: [PATCH] [FIX] hw_scale: Adam scale wait time When opening the weight screen in PoS it can take up to 10 seconds until the weighting starts. This can be resolved by using a Threading.Event instead to reset the 10 second sleep time. Using exit_flag.wait(timeout=DELAY) will be more responsive, because you'll break out of the while loop instantly when exit_flag is set. With time.sleep(timeout=DELAY), even after the event is set, you're going to wait around in the time.sleep call until you've slept for DELAY seconds. closes odoo/odoo#32389 Signed-off-by: Olivier Dony (odo) --- addons/hw_scale/controllers/main.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/addons/hw_scale/controllers/main.py b/addons/hw_scale/controllers/main.py index bb98a8521d0..1ebb6e39af2 100644 --- a/addons/hw_scale/controllers/main.py +++ b/addons/hw_scale/controllers/main.py @@ -8,7 +8,7 @@ import time from collections import namedtuple from os import listdir -from threading import Thread, Lock +from threading import Event, Lock, Thread from odoo import http @@ -134,6 +134,7 @@ class Scale(Thread): self.path_to_scale = '' self.protocol = None self.disabled = False + self.weight_request_event = Event() def lockedstart(self): with self.lock: @@ -261,8 +262,8 @@ class Scale(Thread): return None def get_weight(self): - self.repeats = 5 self.disabled = False + self.weight_request_event.set() self.lockedstart() return self.weight @@ -361,11 +362,13 @@ class Scale(Thread): self.device = self.get_device() if not self.device: # retry later to support "plug and play" - time.sleep(10) + self.weight_request_event.clear() + self.weight_request_event.wait(10) else: self.disabled = self.protocol.disable else: - time.sleep(10) + self.weight_request_event.clear() + self.weight_request_event.wait(10) scale_thread = None