Skip to content

Commit

Permalink
Address review comments: simplify & comment.
Browse files Browse the repository at this point in the history
Thanks Eric!
  • Loading branch information
gpshead committed Nov 10, 2024
1 parent 7d41b16 commit 6bb9db4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
5 changes: 1 addition & 4 deletions Lib/multiprocessing/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,7 @@ def close(self):

def _detach(self):
"""Stop managing the underlying file descriptor or handle."""
try:
return self._handle
finally:
self._handle = None
self._handle = None

def send_bytes(self, buf, offset=0, size=None):
"""Send the bytes data from a bytes-like object"""
Expand Down
26 changes: 15 additions & 11 deletions Lib/multiprocessing/forkserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,19 @@ def connect_to_new_process(self, fds):
resource_tracker.getfd()]
allfds += fds
try:
if self._forkserver_authkey:
client.setblocking(True)
wrapped_client = connection.Connection(client.fileno())
try:
connection.answer_challenge(
wrapped_client, self._forkserver_authkey)
connection.deliver_challenge(
wrapped_client, self._forkserver_authkey)
finally:
wrapped_client._detach()
del wrapped_client
assert self._forkserver_authkey
client.setblocking(True)
wrapped_client = connection.Connection(client.fileno())
# The other side of this exchange happens in the child as
# implemented in main().
try:
connection.answer_challenge(
wrapped_client, self._forkserver_authkey)
connection.deliver_challenge(
wrapped_client, self._forkserver_authkey)
finally:
wrapped_client._detach()
del wrapped_client
reduction.sendfds(client, allfds)
return parent_r, parent_w
except:
Expand Down Expand Up @@ -296,6 +298,8 @@ def sigchld_handler(*_unused):
try:
if authkey:
wrapped_s = connection.Connection(s.fileno())
# The other side of this exchange happens in
# in connect_to_new_process().
try:
connection.deliver_challenge(
wrapped_s, authkey)
Expand Down
4 changes: 2 additions & 2 deletions Lib/test/_test_multiprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -914,8 +914,8 @@ def test_forkserver_auth_is_enabled(self):
addr = forkserver._forkserver_address
self.assertTrue(addr)

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

Expand Down

0 comments on commit 6bb9db4

Please sign in to comment.