File tree Expand file tree Collapse file tree 1 file changed +10
-6
lines changed Expand file tree Collapse file tree 1 file changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -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 ()
154
+ self .handle_close (lock = False )
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 ()
171
+ self .handle_close (lock = True )
172
172
return
173
173
if data :
174
174
self .last_activity = time .time ()
@@ -274,17 +274,21 @@ def _flush_some(self):
274
274
275
275
return False
276
276
277
- def handle_close (self ):
278
- # avoid closing the outbufs while a task is potentially adding data
279
- # to them in write_soon
280
- with self .outbuf_lock :
277
+ def handle_close (self , lock = True ):
278
+ # NB: default to True for when asyncore calls this function directly
279
+ if lock :
280
+ self .outbuf_lock .acquire ()
281
+ try :
281
282
for outbuf in self .outbufs :
282
283
try :
283
284
outbuf .close ()
284
285
except :
285
286
self .logger .exception (
286
287
'Unknown exception while trying to close outbuf' )
287
288
self .connected = False
289
+ finally :
290
+ if lock :
291
+ self .outbuf_lock .release ()
288
292
wasyncore .dispatcher .close (self )
289
293
290
294
def add_channel (self , map = None ):
You can’t perform that action at this time.
0 commit comments