From 844cd231ab21e143c1fefdb3111cf59f486b06bb Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 13 Sep 2017 03:58:25 -0700 Subject: [PATCH 1/2] 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) --- Lib/test/test_ftplib.py | 9 +++++++++ Lib/test/test_poplib.py | 7 ++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_ftplib.py b/Lib/test/test_ftplib.py index a561e9efa0363a..5643e256b66e8a 100644 --- a/Lib/test/test_ftplib.py +++ b/Lib/test/test_ftplib.py @@ -470,6 +470,9 @@ def setUp(self): 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 @@ def setUp(self): 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 @@ def setUp(self): 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) diff --git a/Lib/test/test_poplib.py b/Lib/test/test_poplib.py index 6bc9739780855c..1269199423c0ce 100644 --- a/Lib/test/test_poplib.py +++ b/Lib/test/test_poplib.py @@ -254,6 +254,8 @@ def setUp(self): 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 @@ def tearDown(self): # 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 @@ def setUp(self): 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() From 892cba0db50d384c0f929976488883463023a7f1 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 13 Sep 2017 06:43:58 -0700 Subject: [PATCH 2/2] 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 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Lib/test/test_ftplib.py b/Lib/test/test_ftplib.py index 5643e256b66e8a..b593313db0950a 100644 --- a/Lib/test/test_ftplib.py +++ b/Lib/test/test_ftplib.py @@ -988,6 +988,8 @@ def setUp(self): 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: