mirror of
https://github.com/python/cpython.git
synced 2025-09-02 23:18:25 +00:00
asyncio: Fix upstream issue 168: StreamReader.read(-1) from pipe may hang if data exceeds buffer limit.
This commit is contained in:
parent
a869fd3dc0
commit
bf88ffba5e
2 changed files with 47 additions and 6 deletions
|
@ -419,12 +419,17 @@ class StreamReader:
|
|||
return b''
|
||||
|
||||
if n < 0:
|
||||
while not self._eof:
|
||||
self._waiter = self._create_waiter('read')
|
||||
try:
|
||||
yield from self._waiter
|
||||
finally:
|
||||
self._waiter = None
|
||||
# This used to just loop creating a new waiter hoping to
|
||||
# collect everything in self._buffer, but that would
|
||||
# deadlock if the subprocess sends more than self.limit
|
||||
# bytes. So just call self.read(self._limit) until EOF.
|
||||
blocks = []
|
||||
while True:
|
||||
block = yield from self.read(self._limit)
|
||||
if not block:
|
||||
break
|
||||
blocks.append(block)
|
||||
return b''.join(blocks)
|
||||
else:
|
||||
if not self._buffer and not self._eof:
|
||||
self._waiter = self._create_waiter('read')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue