admin avatar

pytyrant-timeout.patch

🕜 by admin

解决pytyrant.py socket 超时的问题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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
-    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

写一条评论

Based on Golang + fastHTTP + sdb | go1.16.3 Processed in 2ms