Skip to content

Commit 6bb9db4

Browse files
committed
Address review comments: simplify & comment.
Thanks Eric!
1 parent 7d41b16 commit 6bb9db4

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

Lib/multiprocessing/connection.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,7 @@ def close(self):
183183

184184
def _detach(self):
185185
"""Stop managing the underlying file descriptor or handle."""
186-
try:
187-
return self._handle
188-
finally:
189-
self._handle = None
186+
self._handle = None
190187

191188
def send_bytes(self, buf, offset=0, size=None):
192189
"""Send the bytes data from a bytes-like object"""

Lib/multiprocessing/forkserver.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,19 @@ def connect_to_new_process(self, fds):
9797
resource_tracker.getfd()]
9898
allfds += fds
9999
try:
100-
if self._forkserver_authkey:
101-
client.setblocking(True)
102-
wrapped_client = connection.Connection(client.fileno())
103-
try:
104-
connection.answer_challenge(
105-
wrapped_client, self._forkserver_authkey)
106-
connection.deliver_challenge(
107-
wrapped_client, self._forkserver_authkey)
108-
finally:
109-
wrapped_client._detach()
110-
del wrapped_client
100+
assert self._forkserver_authkey
101+
client.setblocking(True)
102+
wrapped_client = connection.Connection(client.fileno())
103+
# The other side of this exchange happens in the child as
104+
# implemented in main().
105+
try:
106+
connection.answer_challenge(
107+
wrapped_client, self._forkserver_authkey)
108+
connection.deliver_challenge(
109+
wrapped_client, self._forkserver_authkey)
110+
finally:
111+
wrapped_client._detach()
112+
del wrapped_client
111113
reduction.sendfds(client, allfds)
112114
return parent_r, parent_w
113115
except:
@@ -296,6 +298,8 @@ def sigchld_handler(*_unused):
296298
try:
297299
if authkey:
298300
wrapped_s = connection.Connection(s.fileno())
301+
# The other side of this exchange happens in
302+
# in connect_to_new_process().
299303
try:
300304
connection.deliver_challenge(
301305
wrapped_s, authkey)

Lib/test/_test_multiprocessing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -914,8 +914,8 @@ def test_forkserver_auth_is_enabled(self):
914914
addr = forkserver._forkserver_address
915915
self.assertTrue(addr)
916916

917-
# First, demonstrate that a raw auth handshake as Client makes
918-
# does not raise an error.
917+
# Demonstrate that a raw auth handshake, as Client performs, does not
918+
# raise an error.
919919
client = multiprocessing.connection.Client(addr, authkey=authkey)
920920
client.close()
921921

0 commit comments

Comments
 (0)