Example #1
1
    def __init__(self, hostName, userName, passwd, dbName, port=3306, maxQueueSize=3):
        """
    set MySQL connection parameters and try to connect
    """
        global gInstancesCount
        gInstancesCount += 1

        self._connected = False

        if "logger" not in dir(self):
            self.logger = gLogger.getSubLogger("MySQL")

        # let the derived class decide what to do with if is not 1
        self._threadsafe = MySQLdb.thread_safe()
        self.logger.debug("thread_safe = %s" % self._threadsafe)

        _checkQueueSize(maxQueueSize)

        self.__hostName = str(hostName)
        self.__userName = str(userName)
        self.__passwd = str(passwd)
        self.__dbName = str(dbName)
        self.__port = port
        # Create the connection Queue to reuse connections
        self.__connectionQueue = Queue.Queue(maxQueueSize)
        # Create the connection Semaphore to limit total number of open connection
        self.__connectionSemaphore = threading.Semaphore(maxQueueSize)

        self.__initialized = True
        self._connect()
Example #2
1
 def get_connection(self, path, log=None, user=None, password=None, host=None, port=None, params={}):
     cnx = MySQLConnection(path, log, user, password, host, port, params)
     if not self.required:
         self._mysql_version = 'server: "%s", client: "%s", thread-safe: %s' % (
             cnx.cnx.get_server_info(),
             MySQLdb.get_client_info(),
             MySQLdb.thread_safe(),
         )
         self.required = True
     return cnx
Example #3
1
 def get_connection(self, path, log=None, user=None, password=None, host=None, port=None, params={}):
     cnx = MySQLConnection(path, log, user, password, host, port, params)
     if not self._version:
         self._version = get_pkginfo(MySQLdb).get("version", MySQLdb.__version__)
         mysql_info = 'server: "%s", client: "%s", thread-safe: %s' % (
             cnx.cnx.get_server_info(),
             MySQLdb.get_client_info(),
             MySQLdb.thread_safe(),
         )
         self.env.systeminfo.extend([("MySQL", mysql_info), ("MySQLdb", self._version)])
     return cnx