Skip to content

Commit 7c29ae1

Browse files
authored
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).
1 parent 62ec638 commit 7c29ae1

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

Lib/multiprocessing/managers.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,8 @@ def accepter(self):
192192
t.daemon = True
193193
t.start()
194194

195-
def handle_request(self, c):
196-
'''
197-
Handle a new connection
198-
'''
199-
funcname = result = request = None
195+
def _handle_request(self, c):
196+
request = None
200197
try:
201198
connection.deliver_challenge(c, self.authkey)
202199
connection.answer_challenge(c, self.authkey)
@@ -213,6 +210,7 @@ def handle_request(self, c):
213210
msg = ('#TRACEBACK', format_exc())
214211
else:
215212
msg = ('#RETURN', result)
213+
216214
try:
217215
c.send(msg)
218216
except Exception as e:
@@ -224,7 +222,17 @@ def handle_request(self, c):
224222
util.info(' ... request was %r', request)
225223
util.info(' ... exception was %r', e)
226224

227-
c.close()
225+
def handle_request(self, conn):
226+
'''
227+
Handle a new connection
228+
'''
229+
try:
230+
self._handle_request(conn)
231+
except SystemExit:
232+
# Server.serve_client() calls sys.exit(0) on EOF
233+
pass
234+
finally:
235+
conn.close()
228236

229237
def serve_client(self, conn):
230238
'''
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The :mod:`multiprocessing` ``Server`` class now explicitly catchs
2+
:exc:`SystemExit` and closes the client connection in this case. It happens
3+
when the ``Server.serve_client()`` method reachs the end of file (EOF).

0 commit comments

Comments
 (0)