Beispiel #1
0
                global_vars["sql_lock"].release()

        ### try to wait for 1s, other threads may release the connection
        if conn is None and global_vars["sql_connection_num"] > 0:
            try:
                conn = global_vars["sql_connections"].get(timeout=1)
            except Exception, e:
                pass

        if conn is not None:
            # check the connection is still alive
            connected = SQLConnManager.TestSQLConnection(conn)

            if not connected:
                logger.debug(
                    "An existing database connection in the connection pool has been disconnected by remote server, recreate a new connection. we have %d live connections"
                    % global_vars["sql_connection_num"])
                try:
                    conn.close()
                except:
                    pass
                conn = SQLConnManager.Connect()

        if conn is None and global_vars[
                "sql_connection_num"] <= sql_max_connect_num:
            conn = SQLConnManager.Connect()
            acquired = global_vars["sql_lock"].acquire()
            try:
                global_vars["sql_connection_num"] += 1
            except Exception, e:
                logger.error("Exception: %s" % str(e))