Merge pull request #9 from numerigraphe/7.0-no-lock-in-update-1308635-ls

[IMP] remove useless locking from update()
This commit is contained in:
Pedro M. Baeza
2014-11-14 09:56:55 +01:00

View File

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