]> granicus.if.org Git - python/commitdiff
[3.6] bpo-31234: Fix dangling thread in test_ftp/poplib (#3554)
authorVictor Stinner <victor.stinner@gmail.com>
Wed, 13 Sep 2017 22:56:14 +0000 (15:56 -0700)
committerGitHub <noreply@github.com>
Wed, 13 Sep 2017 22:56:14 +0000 (15:56 -0700)
* bpo-31234: Fix dangling thread in test_ftp/poplib (#3540)

Explicitly clear the server attribute in test_ftplib and test_poplib
to prevent dangling thread.

(cherry picked from commit d403a29c0055de6b03ed5ae7a5c564e1c95a5950)

* bpo-31234: Fix dangling thread in test_ftplib (#3544)

Clear also self.server_thread attribute in TestTimeouts.tearDown().

(cherry picked from commit b157ce1e58b03988ce4340a55d0b856125833cc5)

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

index a561e9efa0363a23155c2491ec52c8c2420fc8df..b593313db0950abdea590cbcdd543fa3e9d91038 100644 (file)
@@ -470,6 +470,9 @@ 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):
         self.assertEqual(len(received), len(expected))
@@ -799,6 +802,9 @@ 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):
         self.assertEqual(self.client.af, socket.AF_INET6)
@@ -857,6 +863,9 @@ 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):
         self.assertNotIsInstance(self.client.sock, ssl.SSLSocket)
@@ -979,6 +988,8 @@ class TestTimeouts(TestCase):
     def tearDown(self):
         ftplib.FTP.port = self.old_port
         self.server_thread.join()
+        # Explicitly clear the attribute to prevent dangling thread
+        self.server_thread = None
 
     def server(self):
         # This method sets the evt 3 times:
index 6bc9739780855cf2c5e7564530a66ab68cec9139..1269199423c0ce40eac94c2e58dbc61af6b52011 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()