diff options
| author | Olivier Dony <odo@openerp.com> | 2011-12-22 22:48:16 +0100 |
|---|---|---|
| committer | Olivier Dony <odo@openerp.com> | 2011-12-22 22:48:16 +0100 |
| commit | 25599f209367e40fbacf27480c4e47d2f397201b (patch) | |
| tree | 5e6a14c8601ba2cb7df2f3b9e73f452e54218812 /openerp/sql_db.py | |
| parent | a58a2a5e180603d29307b39408b6ab270b31a2d3 (diff) | |
| parent | 1156aee52a8950c608054ba883fcf15783c1be92 (diff) | |
[MERGE] sql_db: try to reconnect after db failure, courtesy of Florent Xicluna
bzr revid: odo@openerp.com-20111222214816-brv6iohfblzg2mli
Diffstat (limited to 'openerp/sql_db.py')
| -rw-r--r-- | openerp/sql_db.py | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/openerp/sql_db.py b/openerp/sql_db.py index ab92d7cc21d..63ab2a13fb9 100644 --- a/openerp/sql_db.py +++ b/openerp/sql_db.py @@ -175,18 +175,18 @@ class Cursor(object): self._cnx = pool.borrow(dsn(dbname)) self._obj = self._cnx.cursor(cursor_factory=psycopg1cursor) - self.__closed = False # real initialisation value - self.autocommit(False) if self.sql_log: self.__caller = frame_codeinfo(currentframe(),2) else: self.__caller = False + self.__closed = False # real initialisation value + self.autocommit(False) self.__closer = False self._default_log_exceptions = True def __del__(self): - if not self.__closed: + if not self.__closed and not self._cnx.closed: # Oops. 'self' has not been closed explicitly. # The cursor will be deleted by the garbage collector, # but the database connection is not put back into the connection @@ -390,6 +390,10 @@ class ConnectionPool(object): # free leaked connections for i, (cnx, _) in tools.reverse_enumerate(self._connections): + if cnx.closed: + self._connections.pop(i) + self._debug('Removing closed connection at index %d: %r', i, cnx.dsn) + continue if getattr(cnx, 'leaked', False): delattr(cnx, 'leaked') self._connections.pop(i) |
