[2.7] bpo-31234: Join threads explicitly in tests (#7406)
* Add support.wait_threads_exit(): context manager looping at exit
until the number of threads decreases to its original number.
* Add some missing thread.join()
* test_asyncore.test_send(): call explicitly t.join() because the cleanup
function is only called outside the test method, whereas the method
has a @test_support.reap_threads decorator
* test_hashlib: replace threading.Event with thread.join()
* test_thread:
* Use wait_threads_exit() context manager
* Replace test_support with support
* test_forkinthread(): check child process exit status in the
main thread to better handle error.
diff --git a/Lib/test/test_smtplib.py b/Lib/test/test_smtplib.py
index 1bb6690..703b631 100644
--- a/Lib/test/test_smtplib.py
+++ b/Lib/test/test_smtplib.py
@@ -306,12 +306,14 @@
self.sock.settimeout(15)
self.port = test_support.bind_port(self.sock)
servargs = (self.evt, self.respdata, self.sock)
- threading.Thread(target=server, args=servargs).start()
+ self.thread = threading.Thread(target=server, args=servargs)
+ self.thread.start()
self.evt.wait()
self.evt.clear()
def tearDown(self):
self.evt.wait()
+ self.thread.join()
sys.stdout = self.old_stdout
def testLineTooLong(self):