]> granicus.if.org Git - python/commitdiff
Do not raise exception on close() on account of socket attribute still being None:
authorGiampaolo Rodola' <g.rodola@gmail.com>
Tue, 9 Apr 2013 15:21:25 +0000 (17:21 +0200)
committerGiampaolo Rodola' <g.rodola@gmail.com>
Tue, 9 Apr 2013 15:21:25 +0000 (17:21 +0200)
>>> 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'
>>>

Lib/asyncore.py

index f1466436d1bc7572a4aa2ee3f689e6d35fe2e656..75481ddde0593c48c93dd3e3aeedc18913993003 100644 (file)
@@ -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.