From 37c469c5cd4f49c4f816db190caf6e64b19a4222 Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Sat, 29 Mar 2014 15:41:46 +0100 Subject: [PATCH] [FIX] hw_{scanner,escpos}: ensure we always release the lock. [FIX] hw_scanner: mark the thread as deamon. bzr revid: chs@openerp.com-20140329144146-utr8gexna4un65u1 --- addons/hw_escpos/controllers/main.py | 9 ++++----- addons/hw_scanner/controllers/main.py | 8 ++++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/addons/hw_escpos/controllers/main.py b/addons/hw_escpos/controllers/main.py index 58c02ebf59f..886b3a96431 100644 --- a/addons/hw_escpos/controllers/main.py +++ b/addons/hw_escpos/controllers/main.py @@ -51,11 +51,10 @@ class EscposDriver(Thread): return connected def lockedstart(self): - self.lock.acquire() - if not self.isAlive(): - self.daemon = True - self.start() - self.lock.release() + with self.lock: + if not self.isAlive(): + self.daemon = True + self.start() def get_escpos_printer(self): try: diff --git a/addons/hw_scanner/controllers/main.py b/addons/hw_scanner/controllers/main.py index 8fbdae62db6..5c9cb50e906 100644 --- a/addons/hw_scanner/controllers/main.py +++ b/addons/hw_scanner/controllers/main.py @@ -88,10 +88,10 @@ class Scanner(Thread): } def lockedstart(self): - self.lock.acquire() - if not self.isAlive(): - self.start() - self.lock.release() + with self.lock: + if not self.isAlive(): + self.daemon = True + self.start() def set_status(self, status, message = None): if status == self.status['status']: