[Python-checkins] bpo-31234: Fix dangling thread in test_ftp/poplib (#3540)

Victor Stinner webhook-mailer at python.org
Wed Sep 13 06:58:28 EDT 2017


https://github.com/python/cpython/commit/d403a29c0055de6b03ed5ae7a5c564e1c95a5950
commit: d403a29c0055de6b03ed5ae7a5c564e1c95a5950
branch: master
author: Victor Stinner <victor.stinner at gmail.com>
committer: GitHub <noreply at github.com>
date: 2017-09-13T03:58:25-07:00
summary:

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.

files:
M Lib/test/test_ftplib.py
M Lib/test/test_poplib.py

diff --git a/Lib/test/test_ftplib.py b/Lib/test/test_ftplib.py
index 151e0919066..372282b4faf 100644
--- a/Lib/test/test_ftplib.py
+++ b/Lib/test/test_ftplib.py
@@ -470,6 +470,8 @@ 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):
@@ -800,6 +802,8 @@ 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):
@@ -859,6 +863,8 @@ 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):
diff --git a/Lib/test/test_poplib.py b/Lib/test/test_poplib.py
index 92febbf83fc..d7a26bc14c9 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()



More information about the Python-checkins mailing list