def connect_thread(self, sleep_time=0): time.sleep(sleep_time) try: while connect_control.allow_connect(): #if self.new_conn_pool.qsize() > self.connection_pool_min: if self.getter_num == 0 or self.new_conn_pool.qsize( ) > self.connection_pool_min: break ip_str = ip_manager.get_gws_ip() if not ip_str: xlog.warning("no enough ip") time.sleep(10) break ssl_sock = self._create_ssl_connection((ip_str, 443)) if not ssl_sock: continue self.new_conn_pool.put((ssl_sock.handshake_time, ssl_sock)) time.sleep(1) finally: self.thread_num_lock.acquire() self.thread_num -= 1 self.thread_num_lock.release()
def connect_thread(self, sleep_time=0): time.sleep(sleep_time) try: while connect_control.allow_connect(): if self.new_conn_pool.qsize() > self.connection_pool_min: break ip_str = ip_manager.get_gws_ip() if not ip_str: xlog.warning("no enough ip") time.sleep(60) break ssl_sock = self._create_ssl_connection( (ip_str, 443) ) if not ssl_sock: continue self.new_conn_pool.put((ssl_sock.handshake_time, ssl_sock)) time.sleep(1) finally: self.thread_num_lock.acquire() self.thread_num -= 1 self.thread_num_lock.release()