Skip to content

Commit

Permalink
gh-129205: Update multiprocessing.forkserver to use os.readinto() (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
cmaloney authored Jan 30, 2025
1 parent 510fefd commit 10ee2d9
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions Lib/multiprocessing/forkserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,13 +382,14 @@ def _serve_one(child_r, fds, unused_fds, handlers):
#

def read_signed(fd):
data = b''
length = SIGNED_STRUCT.size
while len(data) < length:
s = os.read(fd, length - len(data))
if not s:
data = bytearray(SIGNED_STRUCT.size)
unread = memoryview(data)
while unread:
count = os.readinto(fd, unread)
if count == 0:
raise EOFError('unexpected EOF')
data += s
unread = unread[count:]

return SIGNED_STRUCT.unpack(data)[0]

def write_signed(fd, n):
Expand Down

0 comments on commit 10ee2d9

Please sign in to comment.