From 9248a2db18b483cbcd403558a6fb7ab75d5e9a8b Mon Sep 17 00:00:00 2001 From: Antony Lesuisse Date: Wed, 22 Jan 2014 23:15:25 +0100 Subject: [PATCH] [FIX] multiprocess mode, empty the cursor pool before forking bzr revid: al@openerp.com-20140122221525-hify023pk5i8d0jm --- openerp/service/server.py | 3 ++- openerp/sql_db.py | 12 +++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/openerp/service/server.py b/openerp/service/server.py index 87f10010645..6a558a24e91 100644 --- a/openerp/service/server.py +++ b/openerp/service/server.py @@ -182,7 +182,6 @@ class CommonServer(object): # runtime self.pid = os.getpid() - def close_socket(self, sock): """ Closes a socket instance cleanly :param sock: the network socket to close @@ -530,6 +529,8 @@ class PreforkServer(CommonServer): raise def start(self): + # Empty the cursor pool, we dont want them to be shared among forked workers. + openerp.sql_db.close_all() # wakeup pipe, python doesnt throw EINTR when a syscall is interrupted # by a signal simulating a pseudo SA_RESTART. We write to a pipe in the # signal handler to overcome this behaviour diff --git a/openerp/sql_db.py b/openerp/sql_db.py index 7a58a5fc515..de9d21dcd82 100644 --- a/openerp/sql_db.py +++ b/openerp/sql_db.py @@ -27,9 +27,6 @@ the database, *not* a database abstraction toolkit. Database abstraction is what the ORM does, in fact. """ - -__all__ = ['db_connect', 'close_db'] - from functools import wraps import logging import psycopg2.extensions @@ -457,10 +454,10 @@ class ConnectionPool(object): raise PoolError('This connection does not below to the pool') @locked - def close_all(self, dsn): + def close_all(self, dsn=None): _logger.info('%r: Close all connections to %r', self, dsn) for i, (cnx, used) in tools.reverse_enumerate(self._connections): - if dsn_are_equals(cnx.dsn, dsn): + if dsn is None or dsn_are_equals(cnx.dsn, dsn): cnx.close() self._connections.pop(i) @@ -522,6 +519,11 @@ def close_db(db_name): if _Pool: _Pool.close_all(dsn(db_name)) +def close_all(): + global _Pool + if _Pool: + _Pool.close_all() + # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: