]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-129205: Update multiprocessing.forkserver to use os.readinto() (#129425)
authorCody Maloney <cmaloney@users.noreply.github.com>
Thu, 30 Jan 2025 22:24:52 +0000 (14:24 -0800)
committerGitHub <noreply@github.com>
Thu, 30 Jan 2025 22:24:52 +0000 (22:24 +0000)
Lib/multiprocessing/forkserver.py

index df9b9be9d1898b3c5542322e0d4ddf0521f40377..681af2610e9b37da648327af1a26a57a308b7acd 100644 (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):