From 32f239fa6b911c57d468b6cf872f3aae127f4541 Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Tue, 8 Dec 2009 18:27:59 +0100 Subject: [FIX] better locking when accessing to template1 database bzr revid: chs@tinyerp.com-20091208172759-wncaqjguglwgf634 --- bin/sql_db.py | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'bin/sql_db.py') diff --git a/bin/sql_db.py b/bin/sql_db.py index 59d7bcaac1f..e39b40a1ee6 100644 --- a/bin/sql_db.py +++ b/bin/sql_db.py @@ -294,17 +294,31 @@ class Connection(object): self.dbname = dbname self._pool = pool self._unique = unique - if unique: - if dbname not in self.__LOCKS: - self.__LOCKS[dbname] = threading.Lock() - self.__LOCKS[dbname].acquire() - def __del__(self): + def __enter__(self): + if self._unique: + self.lock() + return self + + def __exit__(self, exc_type, exc_value, traceback): if self._unique: - close_db(self.dbname) - self.__LOCKS[self.dbname].release() + self.release() + + def lock(self): + if self.dbname not in self.__LOCKS: + self.__LOCKS[self.dbname] = threading.Lock() + self.__LOCKS[self.dbname].acquire() + + def release(self): + close_db(self.dbname) + self.__LOCKS[self.dbname].release() def cursor(self, serialized=False): + if self._unique: + lock = self.__LOCKS.get(self.dbname, None) + if not (lock and lock.locked()): + netsvc.Logger().notifyChannel('Connection', netsvc.LOG_WARNING, 'Unprotected connection to %s' % (self.dbname,)) + return Cursor(self._pool, self.dbname, serialized=serialized) def serialized_cursor(self): -- cgit v1.2.3 From 89be98debf3ff15b80dfc4231c7d2831e47c1da7 Mon Sep 17 00:00:00 2001 From: Fabien Pinckaers Date: Tue, 22 Dec 2009 22:20:36 +0100 Subject: [FIX] multi company, speed improvement bzr revid: fp@tinyerp.com-20091222212036-oeekt3f06k5j0ize --- bin/sql_db.py | 1 - 1 file changed, 1 deletion(-) (limited to 'bin/sql_db.py') diff --git a/bin/sql_db.py b/bin/sql_db.py index a84547b0b7c..b4ce8347f43 100644 --- a/bin/sql_db.py +++ b/bin/sql_db.py @@ -82,7 +82,6 @@ class Cursor(object): self.sql_into_log = {} self.sql_log = False self.sql_log_count = 0 - self.__closed = True # avoid the call of close() (by __del__) if an exception # is raised by any of the following initialisations self._pool = pool -- cgit v1.2.3