diff options
author | Victor Stinner <vstinner@python.org> | 2021-04-16 17:42:34 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-16 17:42:34 (GMT) |
commit | 7c29ae1f0585378dba4d220a2c0fb5dd49fdab3e (patch) | |
tree | b02839b2fdec7e81707bd28bdbba5cb8715174c1 | |
parent | 62ec63864822de1dd1933225584e8503ac40c1f9 (diff) | |
download | cpython-7c29ae1f0585378dba4d220a2c0fb5dd49fdab3e.zip cpython-7c29ae1f0585378dba4d220a2c0fb5dd49fdab3e.tar.gz cpython-7c29ae1f0585378dba4d220a2c0fb5dd49fdab3e.tar.bz2 |
bpo-43867: multiprocessing Server catchs SystemExit (GH-25441)
The multiprocessing Server class now explicitly catchs SystemExit and
closes the client connection in this case. It happens when the
Server.serve_client() method reachs the end of file (EOF).
-rw-r--r-- | Lib/multiprocessing/managers.py | 20 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Library/2021-04-16-16-46-44.bpo-43867.xT9QjF.rst | 3 |
2 files changed, 17 insertions, 6 deletions
diff --git a/Lib/multiprocessing/managers.py b/Lib/multiprocessing/managers.py index 0eb16c6..6ee9521 100644 --- a/Lib/multiprocessing/managers.py +++ b/Lib/multiprocessing/managers.py @@ -192,11 +192,8 @@ class Server(object): t.daemon = True t.start() - def handle_request(self, c): - ''' - Handle a new connection - ''' - funcname = result = request = None + def _handle_request(self, c): + request = None try: connection.deliver_challenge(c, self.authkey) connection.answer_challenge(c, self.authkey) @@ -213,6 +210,7 @@ class Server(object): msg = ('#TRACEBACK', format_exc()) else: msg = ('#RETURN', result) + try: c.send(msg) except Exception as e: @@ -224,7 +222,17 @@ class Server(object): util.info(' ... request was %r', request) util.info(' ... exception was %r', e) - c.close() + def handle_request(self, conn): + ''' + Handle a new connection + ''' + try: + self._handle_request(conn) + except SystemExit: + # Server.serve_client() calls sys.exit(0) on EOF + pass + finally: + conn.close() def serve_client(self, conn): ''' diff --git a/Misc/NEWS.d/next/Library/2021-04-16-16-46-44.bpo-43867.xT9QjF.rst b/Misc/NEWS.d/next/Library/2021-04-16-16-46-44.bpo-43867.xT9QjF.rst new file mode 100644 index 0000000..1ec914e --- /dev/null +++ b/Misc/NEWS.d/next/Library/2021-04-16-16-46-44.bpo-43867.xT9QjF.rst @@ -0,0 +1,3 @@ +The :mod:`multiprocessing` ``Server`` class now explicitly catchs +:exc:`SystemExit` and closes the client connection in this case. It happens +when the ``Server.serve_client()`` method reachs the end of file (EOF). |