[Python-checkins] bpo-44359: Fix test_ftplib unhandled thread exceptions (GH-31069)
miss-islington
webhook-mailer at python.org
Tue Feb 1 21:12:35 EST 2022
https://github.com/python/cpython/commit/85b421fbff23ff41c52fa5bde191920b3701f0d0
commit: 85b421fbff23ff41c52fa5bde191920b3701f0d0
branch: 3.10
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2022-02-01T18:12:27-08:00
summary:
bpo-44359: Fix test_ftplib unhandled thread exceptions (GH-31069)
test_ftplib now silently ignores socket errors to prevent logging
unhandled threading exceptions.
(cherry picked from commit 0611eafc709cbe8a2a0bdde082d25df0c5034de7)
Co-authored-by: Victor Stinner <vstinner at python.org>
files:
A Misc/NEWS.d/next/Tests/2022-02-02-02-24-04.bpo-44359.kPPSmN.rst
M Lib/test/test_ftplib.py
diff --git a/Lib/test/test_ftplib.py b/Lib/test/test_ftplib.py
index 56e3d8ab8528a..2f5cc06ca4b9a 100644
--- a/Lib/test/test_ftplib.py
+++ b/Lib/test/test_ftplib.py
@@ -56,6 +56,13 @@
"type=file;perm=r;unique==SGP2; file \xAE non-ascii char\r\n")
+def default_error_handler():
+ # bpo-44359: Silently ignore socket errors. Such errors occur when a client
+ # socket is closed, in TestFTPClass.tearDown() and makepasv() tests, and
+ # the server gets an error on its side.
+ pass
+
+
class DummyDTPHandler(asynchat.async_chat):
dtp_conn_closed = False
@@ -87,7 +94,7 @@ def push(self, what):
super(DummyDTPHandler, self).push(what.encode(self.encoding))
def handle_error(self):
- raise Exception
+ default_error_handler()
class DummyFTPHandler(asynchat.async_chat):
@@ -137,7 +144,7 @@ def found_terminator(self):
self.push('550 command "%s" not understood.' %cmd)
def handle_error(self):
- raise Exception
+ default_error_handler()
def push(self, data):
asynchat.async_chat.push(self, data.encode(self.encoding) + b'\r\n')
@@ -315,7 +322,7 @@ def writable(self):
return 0
def handle_error(self):
- raise Exception
+ default_error_handler()
if ssl is not None:
@@ -418,7 +425,7 @@ def recv(self, buffer_size):
raise
def handle_error(self):
- raise Exception
+ default_error_handler()
def close(self):
if (isinstance(self.socket, ssl.SSLSocket) and
diff --git a/Misc/NEWS.d/next/Tests/2022-02-02-02-24-04.bpo-44359.kPPSmN.rst b/Misc/NEWS.d/next/Tests/2022-02-02-02-24-04.bpo-44359.kPPSmN.rst
new file mode 100644
index 0000000000000..00c29b1ca4089
--- /dev/null
+++ b/Misc/NEWS.d/next/Tests/2022-02-02-02-24-04.bpo-44359.kPPSmN.rst
@@ -0,0 +1,2 @@
+test_ftplib now silently ignores socket errors to prevent logging unhandled
+threading exceptions. Patch by Victor Stinner.
More information about the Python-checkins
mailing list