Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a4c377c

Browse files
committed
Do not raise exception on close() on account of socket attribute still being None:
>>> import asyncore >>> d = asyncore.dispatcher() >>> d.close() Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python3.4/asyncore.py", line 401, in close self.socket.close() AttributeError: 'NoneType' object has no attribute 'close' >>>
1 parent fa1b02a commit a4c377c

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

Lib/asyncore.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -397,11 +397,12 @@ def close(self):
397397
self.accepting = False
398398
self.connecting = False
399399
self.del_channel()
400-
try:
401-
self.socket.close()
402-
except OSError as why:
403-
if why.args[0] not in (ENOTCONN, EBADF):
404-
raise
400+
if self.socket is not None:
401+
try:
402+
self.socket.close()
403+
except OSError as why:
404+
if why.args[0] not in (ENOTCONN, EBADF):
405+
raise
405406

406407
# cheap inheritance, used to pass all other attribute
407408
# references to the underlying socket object.

0 commit comments

Comments
 (0)