[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) <odo@openerp.com>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user