gh-129205: Update multiprocessing.forkserver to use os.readinto() (#129425)

This commit is contained in:
Cody Maloney 2025-01-30 14:24:52 -08:00 committed by GitHub
parent 510fefdc62
commit 10ee2d9d3b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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):