@@ -96,8 +96,11 @@ def get_extra_info(self, name: str, default=None): # type: ignore[override]
9696 return default
9797
9898
99- async def _windows_stdio_streams (loop : asyncio .AbstractEventLoop ) -> tuple [asyncio .StreamReader , asyncio .StreamWriter ]:
100- reader = asyncio .StreamReader ()
99+ async def _windows_stdio_streams (
100+ loop : asyncio .AbstractEventLoop ,
101+ limit : int | None = None ,
102+ ) -> tuple [asyncio .StreamReader , asyncio .StreamWriter ]:
103+ reader = asyncio .StreamReader (limit = limit ) if limit is not None else asyncio .StreamReader ()
101104 _ = asyncio .StreamReaderProtocol (reader )
102105
103106 _start_stdin_feeder (loop , reader )
@@ -108,9 +111,12 @@ async def _windows_stdio_streams(loop: asyncio.AbstractEventLoop) -> tuple[async
108111 return reader , writer
109112
110113
111- async def _posix_stdio_streams (loop : asyncio .AbstractEventLoop ) -> tuple [asyncio .StreamReader , asyncio .StreamWriter ]:
114+ async def _posix_stdio_streams (
115+ loop : asyncio .AbstractEventLoop ,
116+ limit : int | None = None ,
117+ ) -> tuple [asyncio .StreamReader , asyncio .StreamWriter ]:
112118 # Reader from stdin
113- reader = asyncio .StreamReader ()
119+ reader = asyncio .StreamReader (limit = limit ) if limit is not None else asyncio . StreamReader ( )
114120 reader_protocol = asyncio .StreamReaderProtocol (reader )
115121 await loop .connect_read_pipe (lambda : reader_protocol , sys .stdin )
116122
@@ -121,12 +127,16 @@ async def _posix_stdio_streams(loop: asyncio.AbstractEventLoop) -> tuple[asyncio
121127 return reader , writer
122128
123129
124- async def stdio_streams () -> tuple [asyncio .StreamReader , asyncio .StreamWriter ]:
125- """Create stdio asyncio streams; on Windows use a thread feeder + custom stdout transport."""
130+ async def stdio_streams (limit : int | None = None ) -> tuple [asyncio .StreamReader , asyncio .StreamWriter ]:
131+ """Create stdio asyncio streams; on Windows use a thread feeder + custom stdout transport.
132+
133+ Args:
134+ limit: Optional buffer limit for the stdin reader.
135+ """
126136 loop = asyncio .get_running_loop ()
127137 if platform .system () == "Windows" :
128- return await _windows_stdio_streams (loop )
129- return await _posix_stdio_streams (loop )
138+ return await _windows_stdio_streams (loop , limit = limit )
139+ return await _posix_stdio_streams (loop , limit = limit )
130140
131141
132142@asynccontextmanager
0 commit comments