File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change 7
7
8
8
import msgpack
9
9
10
+ SEND_FAIL_SEC = 3
11
+ MAX_SEND_FAIL = 30
12
+
10
13
11
14
_global_sender = None
12
15
@@ -41,6 +44,8 @@ def __init__(self,
41
44
42
45
self .socket = None
43
46
self .pendings = None
47
+ self .last_send_fail = None
48
+ self .send_fail_cnt = 0
44
49
self .lock = threading .Lock ()
45
50
46
51
try :
@@ -89,16 +94,25 @@ def _send_internal(self, bytes_):
89
94
90
95
# send finished
91
96
self .pendings = None
97
+ self .last_send_fail = None
98
+ self .send_fail_cnt = 0
92
99
except Exception :
93
100
# close socket
94
101
self ._close ()
102
+ self .send_fail_cnt += 1
95
103
# clear buffer if it exceeds max bufer size
96
- if self .pendings and (len (self .pendings ) > self .bufmax ):
104
+ if self .send_fail_cnt > MAX_SEND_FAIL :
105
+ raise
106
+ if self .last_send_fail and time .time () - self .last_send_fail > SEND_FAIL_SEC :
107
+ raise
108
+ elif self .pendings and (len (self .pendings ) > self .bufmax ):
97
109
# TODO: add callback handler here
98
110
self .pendings = None
99
111
raise
100
112
else :
101
113
self .pendings = bytes_
114
+ if self .last_send_fail is None :
115
+ self .last_send_fail = time .time ()
102
116
103
117
def _reconnect (self ):
104
118
if not self .socket :
You can’t perform that action at this time.
0 commit comments