]> granicus.if.org Git - python/commitdiff
bpo-31234: Fix dangling thread in test_ftp/poplib (#3540)
authorVictor Stinner <victor.stinner@gmail.com>
Wed, 13 Sep 2017 10:58:25 +0000 (03:58 -0700)
committerGitHub <noreply@github.com>
Wed, 13 Sep 2017 10:58:25 +0000 (03:58 -0700)
Explicitly clear the server attribute in test_ftplib and test_poplib
to prevent dangling thread.

Lib/test/test_ftplib.py
Lib/test/test_poplib.py

index 151e09190669a5dc800ea67178975308c4d84c41..372282b4faf062212c85697b97e04739630b801e 100644 (file)
@@ -470,6 +470,8 @@ class TestFTPClass(TestCase):
     def tearDown(self):
         self.client.close()
         self.server.stop()
+        # Explicitly clear the attribute to prevent dangling thread
+        self.server = None
         asyncore.close_all(ignore_all=True)
 
     def check_data(self, received, expected):
@@ -800,6 +802,8 @@ class TestIPv6Environment(TestCase):
     def tearDown(self):
         self.client.close()
         self.server.stop()
+        # Explicitly clear the attribute to prevent dangling thread
+        self.server = None
         asyncore.close_all(ignore_all=True)
 
     def test_af(self):
@@ -859,6 +863,8 @@ class TestTLS_FTPClass(TestCase):
     def tearDown(self):
         self.client.close()
         self.server.stop()
+        # Explicitly clear the attribute to prevent dangling thread
+        self.server = None
         asyncore.close_all(ignore_all=True)
 
     def test_control_connection(self):
index 92febbf83fcfdb2b4d4c5537abb8701550f152c9..d7a26bc14c9197764ce3b7dcfacde2051d088cdd 100644 (file)
@@ -254,6 +254,8 @@ class TestPOP3Class(TestCase):
     def tearDown(self):
         self.client.close()
         self.server.stop()
+        # Explicitly clear the attribute to prevent dangling thread
+        self.server = None
 
     def test_getwelcome(self):
         self.assertEqual(self.client.getwelcome(),
@@ -436,6 +438,8 @@ class TestPOP3_TLSClass(TestPOP3Class):
                 # this exception
                 self.client.close()
         self.server.stop()
+        # Explicitly clear the attribute to prevent dangling thread
+        self.server = None
 
     def test_stls(self):
         self.assertRaises(poplib.error_proto, self.client.stls)
@@ -461,7 +465,8 @@ class TestTimeouts(TestCase):
 
     def tearDown(self):
         self.thread.join()
-        del self.thread  # Clear out any dangling Thread objects.
+        # Explicitly clear the attribute to prevent dangling thread
+        self.thread = None
 
     def server(self, evt, serv):
         serv.listen()