]> granicus.if.org Git - python/commitdiff
asyncore: introduce a new 'closed' attribute to make sure that dispatcher gets closed...
authorGiampaolo Rodolà <g.rodola@gmail.com>
Fri, 11 Feb 2011 13:04:18 +0000 (13:04 +0000)
committerGiampaolo Rodolà <g.rodola@gmail.com>
Fri, 11 Feb 2011 13:04:18 +0000 (13:04 +0000)
In different occasions close() might be called more than once, causing problems with already disconnected sockets/dispatchers.

Lib/asyncore.py

index f0712e20615fe91ff7ca4f880f80aab23a6be886..91c629bd0f339e056bf8e0c0565b46b19398128e 100644 (file)
@@ -220,7 +220,7 @@ class dispatcher:
 
     connected = False
     accepting = False
-    closing = False
+    closed = False
     addr = None
     ignore_log_types = frozenset(['warning'])
 
@@ -393,14 +393,16 @@ class dispatcher:
                 raise
 
     def close(self):
-        self.connected = False
-        self.accepting = False
-        self.del_channel()
-        try:
-            self.socket.close()
-        except socket.error as why:
-            if why.args[0] not in (ENOTCONN, EBADF):
-                raise
+        if not self.closed:
+            self.closed = True
+            self.connected = False
+            self.accepting = False
+            self.del_channel()
+            try:
+                self.socket.close()
+            except socket.error 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.