[IMP] remove useless locking from update()

Locking shouldn't be needed here because the data we read is immutable
This commit is contained in:
Lionel Sausin
2014-04-16 17:58:57 +02:00
committed by Lionel Sausin (Numérigraphe)
parent a9ab12a542
commit 06f8bdf222

View File

@@ -155,23 +155,19 @@ class printing_printer(orm.Model):
thread.start()
def update(self, cr, uid, context=None):
if not context or context.get('skip_update'):
return
self.lock.acquire()
"""Update printer status if current status is more than 10s old."""
# We won't acquire locks - we're only assigning from immutable data
if not context or 'skip_update' in context:
return True
last_update = self.last_update
updating = self.updating
self.lock.release()
now = time.time()
# Only update printer status if current status is more than 10 seconds old.
if not last_update or now - last_update > 10:
self.start_printer_update(cr, uid, context)
# Wait up to five seconds for printer status update
for x in range(0, 5):
for _dummy in range(0, 5):
time.sleep(1)
self.lock.acquire()
updating = self.updating
self.lock.release()
if not updating:
if not self.updating:
break
return True