Browse Source

add timeout

David 10 years atrás
parent
commit
17ade07068
1 changed files with 6 additions and 4 deletions
  1. 6 4
      pmanager/pmanager.py

+ 6 - 4
pmanager/pmanager.py

@@ -97,16 +97,18 @@ class PManager:
         except Exception as e:
             print(e)
 
-    def conn(self, target):
+    def conn(self, target, timeout=None):
         if self.ws is None:
             self.ws = websocket.WebSocket()
         try:
             self.ws.connect(target)
         except Exception as e:
             log(e)
-            time.sleep(2)
-            self.conn(target) #keep trying you basterd
-    
+            if timeout is None:
+                timeout = 2
+            timeout = min(timeout, 90)
+            time.sleep(timeout)
+            self.conn(target, timeout+2) #keep trying you basterd
     
     def close(self):
         if self.ws is None: