def init_db_conn(self): """create our MySQL connections""" logging.debug("init_db_conn") try: # Only create it if it doesn't exist if self.db_conn is None and self.db_pool is None: logging.debug("need to create new db_conn") self.db_conn = create_db_conn(self.settings) else: logging.debug("NOT creating db_conn") except Exception: self.set_db_conn(None) logging.debug("error creating db_conn") raise
def init_db_pool(self, pool_size=10): """create our MySQL connections pool. Queue used for pool relies on gevent. """ logging.debug("init_db_pool") try: # Only create it if it doesn't exist if self.db_conn is None and self.db_pool is None: logging.debug("need to create new db_pool") self.db_pool = gevent.queue.Queue() for i in range(pool_size): self.db_pool.put_nowait(create_db_conn(self.settings)) else: logging.debug("NOT creating db_pool") except Exception: self.set_db_pool(None) logging.debug("error creating db_pool") raise