Пример #1
0
 def connect(self):
     while not self.conn:
         self.conn = self.__connect()
         if not self.conn:
             interval = random.randint(0, ss.get("reconnect_interval", MAX_INTERVAL))
             logger.info("connection will be established in %ss" % interval)
             time.sleep(interval)
     return self.conn
Пример #2
0
 def __connect(self):
     conn_cnt = 0
     logger.info("trying to connect to sqlserver hosted on %s:%s" % (ss.get("host"), ss.get("port")))
     while conn_cnt < ss.get("reconnect_times", 3):
         try:
             conn = pymssql.connect(
                 host=ss.get("host"),
                 port=ss.get("port"),
                 user=ss.get("user"),
                 password=ss.get("password"),
                 database=ss.get("database"),
                 charset=ss.get("charset"),
             )
             logger.info("connected to sqlserver")
             return conn
         except Exception, e:  # TODO:add a specified exception
             conn_cnt += 1
             logger.info("connecting failed, times to reconnect: %d" % conn_cnt)