Skip to content

Commit d403a29

Browse files
authored
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.
1 parent b8f4163 commit d403a29

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

Lib/test/test_ftplib.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,8 @@ def setUp(self):
470470
def tearDown(self):
471471
self.client.close()
472472
self.server.stop()
473+
# Explicitly clear the attribute to prevent dangling thread
474+
self.server = None
473475
asyncore.close_all(ignore_all=True)
474476

475477
def check_data(self, received, expected):
@@ -800,6 +802,8 @@ def setUp(self):
800802
def tearDown(self):
801803
self.client.close()
802804
self.server.stop()
805+
# Explicitly clear the attribute to prevent dangling thread
806+
self.server = None
803807
asyncore.close_all(ignore_all=True)
804808

805809
def test_af(self):
@@ -859,6 +863,8 @@ def setUp(self):
859863
def tearDown(self):
860864
self.client.close()
861865
self.server.stop()
866+
# Explicitly clear the attribute to prevent dangling thread
867+
self.server = None
862868
asyncore.close_all(ignore_all=True)
863869

864870
def test_control_connection(self):

Lib/test/test_poplib.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@ def setUp(self):
254254
def tearDown(self):
255255
self.client.close()
256256
self.server.stop()
257+
# Explicitly clear the attribute to prevent dangling thread
258+
self.server = None
257259

258260
def test_getwelcome(self):
259261
self.assertEqual(self.client.getwelcome(),
@@ -436,6 +438,8 @@ def tearDown(self):
436438
# this exception
437439
self.client.close()
438440
self.server.stop()
441+
# Explicitly clear the attribute to prevent dangling thread
442+
self.server = None
439443

440444
def test_stls(self):
441445
self.assertRaises(poplib.error_proto, self.client.stls)
@@ -461,7 +465,8 @@ def setUp(self):
461465

462466
def tearDown(self):
463467
self.thread.join()
464-
del self.thread # Clear out any dangling Thread objects.
468+
# Explicitly clear the attribute to prevent dangling thread
469+
self.thread = None
465470

466471
def server(self, evt, serv):
467472
serv.listen()

0 commit comments

Comments
 (0)