admin
admin
3303 0 0

pytyrant-timeout.patch

解决pytyrant.py socket 超时的问题

Index: pytyrant.py
===================================================================
--- pytyrant.py	(revision 55325)
+++ pytyrant.py	(revision 55326)
@@ -173,7 +173,6 @@
     if fail_code:
         raise TyrantError(fail_code)
 
-
 def socklen(sock):
     return struct.unpack('>I', sockrecv(sock, 4))[0]
 
@@ -353,12 +352,13 @@
 
 class Tyrant(object):
     @[classmethod](/name/classmethod) 
-    def open(cls, host='127.0.0.1', port=DEFAULT_PORT):
+    def open(cls, host='127.0.0.1', port=DEFAULT_PORT, timeout=3.0):
         sock = socket.socket()
+        sock.settimeout(timeout)
         sock.connect((host, port))
         sock.setsockopt(socket.SOL_TCP, socket.TCP_NODELAY, 1)
         return cls(sock)
-
+        
     def __init__(self, sock):
         self.sock = sock

摘菜 https://code.google.com/p/pytyrant/issues/detail?id=13

0

Nearby


Discussion

Login Topics