https://github.com/python/cpython/commit/10ee2d9d3bcde27c75f179214ad41c00e4852a7a
commit: 10ee2d9d3bcde27c75f179214ad41c00e4852a7a
branch: main
author: Cody Maloney <[email protected]>
committer: vstinner <[email protected]>
date: 2025-01-30T22:24:52Z
summary:
gh-129205: Update multiprocessing.forkserver to use os.readinto() (#129425)
files:
M Lib/multiprocessing/forkserver.py
diff --git a/Lib/multiprocessing/forkserver.py
b/Lib/multiprocessing/forkserver.py
index df9b9be9d1898b..681af2610e9b37 100644
--- a/Lib/multiprocessing/forkserver.py
+++ b/Lib/multiprocessing/forkserver.py
@@ -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):
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]