]> granicus.if.org Git - python/commitdiff
Fix test_ftplib warning if IPv6 is not available (#1457)
authorVictor Stinner <victor.stinner@gmail.com>
Thu, 4 May 2017 16:10:30 +0000 (18:10 +0200)
committerGitHub <noreply@github.com>
Thu, 4 May 2017 16:10:30 +0000 (18:10 +0200)
DummyFTPServer now calls del_channel() on bind() error to prevent the
following warning in TestIPv6Environment.setUpClass():

Warning -- asyncore.socket_map was modified by test_ftplib
  Before: {}
  After:  {3: <test.test_ftplib.DummyFTPServer 127.0.0.1:0 at ...>}

Lib/test/test_ftplib.py

index cc1c19bc46877a8504534fda2d50b97081bd1897..044ce4594c971fdcb834b102d650a0667bee6aad 100644 (file)
@@ -218,12 +218,18 @@ class DummyFTPServer(asyncore.dispatcher, threading.Thread):
         threading.Thread.__init__(self)
         asyncore.dispatcher.__init__(self)
         self.create_socket(af, socket.SOCK_STREAM)
-        self.bind(address)
-        self.listen(5)
-        self.active = False
-        self.active_lock = threading.Lock()
-        self.host, self.port = self.socket.getsockname()[:2]
-        self.handler_instance = None
+        try:
+            self.bind(address)
+            self.listen(5)
+            self.active = False
+            self.active_lock = threading.Lock()
+            self.host, self.port = self.socket.getsockname()[:2]
+            self.handler_instance = None
+        except:
+            # unregister the server on bind() error,
+            # needed by TestIPv6Environment.setUpClass()
+            self.del_channel()
+            raise
 
     def start(self):
         assert not self.active