@@ -75,7 +75,7 @@ def __init__(
75
75
# task_lock used to push/pop requests
76
76
self .task_lock = threading .Lock ()
77
77
# outbuf_lock used to access any outbuf
78
- self .outbuf_lock = threading .Lock ()
78
+ self .outbuf_lock = threading .RLock ()
79
79
80
80
wasyncore .dispatcher .__init__ (self , sock , map = map )
81
81
@@ -151,7 +151,7 @@ def handle_write(self):
151
151
self .will_close = True
152
152
153
153
if self .will_close :
154
- self .handle_close (lock = False )
154
+ self .handle_close ()
155
155
156
156
def readable (self ):
157
157
# We might want to create a new task. We can only do this if:
@@ -168,7 +168,7 @@ def handle_read(self):
168
168
except socket .error :
169
169
if self .adj .log_socket_errors :
170
170
self .logger .exception ('Socket error' )
171
- self .handle_close (lock = True )
171
+ self .handle_close ()
172
172
return
173
173
if data :
174
174
self .last_activity = time .time ()
@@ -274,21 +274,16 @@ def _flush_some(self):
274
274
275
275
return False
276
276
277
- def handle_close (self , lock = True ):
277
+ def handle_close (self ):
278
278
# NB: default to True for when asyncore calls this function directly
279
- if lock :
280
- self .outbuf_lock .acquire ()
281
- try :
279
+ with self .outbuf_lock :
282
280
for outbuf in self .outbufs :
283
281
try :
284
282
outbuf .close ()
285
283
except :
286
284
self .logger .exception (
287
285
'Unknown exception while trying to close outbuf' )
288
286
self .connected = False
289
- finally :
290
- if lock :
291
- self .outbuf_lock .release ()
292
287
wasyncore .dispatcher .close (self )
293
288
294
289
def add_channel (self , map = None ):
0 commit comments