Commit 7fa0f945 authored by Giampaolo Rodola's avatar Giampaolo Rodola

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'
>>>
parent 6620853c
......@@ -397,11 +397,12 @@ class dispatcher:
self.accepting = False
self.connecting = False
self.del_channel()
try:
self.socket.close()
except OSError as why:
if why.args[0] not in (ENOTCONN, EBADF):
raise
if self.socket is not None:
try:
self.socket.close()
except OSError as why:
if why.args[0] not in (ENOTCONN, EBADF):
raise
# cheap inheritance, used to pass all other attribute
# references to the underlying socket object.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment