Parcourir la source

Update connection.py

The code should never call sys.exit(),  left the decision for the user of Fdfs_client.
zlk1983 il y a 5 ans
Parent
commit
986ea7b398
1 fichiers modifiés avec 4 ajouts et 2 suppressions
  1. 4 2
      fdfs_client/connection.py

+ 4 - 2
fdfs_client/connection.py

@@ -107,11 +107,11 @@ class ConnectionPool(object):
         """Create a new connection."""
         if self._conns_created >= self.max_conn:
             raise ConnectionError('[-] Error: Too many connections.')
-        num_try = 10
+        num_try = 3
         while True:
             try:
                 if num_try <= 0:
-                    sys.exit()
+                    break
                 conn_instance = self.conn_class(**self.conn_kwargs)
                 conn_instance.connect()
                 self._conns_created += 1
@@ -120,6 +120,8 @@ class ConnectionPool(object):
                 print(e)
                 num_try -= 1
                 conn_instance = None
+        if num_try <= 0:
+            raise ConnectionError("Fail to connect with Fdfs-server after trying %d times" % num_try)
         return conn_instance
 
     def get_connection(self):