[Python-checkins] cpython: Do not raise exception on close() on account of socket attribute still being

giampaolo.rodola python-checkins at python.org
Tue Apr 9 17:23:35 CEST 2013


http://hg.python.org/cpython/rev/37c31fa0c47d
changeset:   83213:37c31fa0c47d
parent:      83208:eb632aafff57
user:        Giampaolo Rodola' <g.rodola at gmail.com>
date:        Tue Apr 09 17:21:25 2013 +0200
summary:
  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'
>>>

files:
  Lib/asyncore.py |  11 ++++++-----
  1 files changed, 6 insertions(+), 5 deletions(-)


diff --git a/Lib/asyncore.py b/Lib/asyncore.py
--- a/Lib/asyncore.py
+++ b/Lib/asyncore.py
@@ -397,11 +397,12 @@
         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.

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list