New submission from Marko <ivanovic.ma...@yandex.com>:
When using asyncio to read from pipe, if process on the other side of pipe crashes read operation hangs indefinitely. Example: import asyncio import contextlib import os import signal import time prx, ctx = os.pipe() read_transport = None read_stream = None async def _connect_read(loop): global read_transport global read_stream stream_reader = asyncio.StreamReader() def protocol_factory(): return asyncio.StreamReaderProtocol(stream_reader) rpipe = os.fdopen(prx, mode='r') transport, _ = await loop.connect_read_pipe(protocol_factory, rpipe) read_transport = transport read_stream = stream_reader def close(): read_transport.close() @contextlib.asynccontextmanager async def connect(): try: loop = asyncio.get_event_loop() await _connect_read(loop) yield finally: close() cpid = os.fork() if cpid == 0: os.kill(os.getpid(), signal.SIGKILL) os.write(ctx, b'A') time.sleep(10.0) else: async def read_from_child(): async with connect(): input = await read_stream.read(1) print('Parent received: ', input) asyncio.run(read_from_child()) ---------- components: Library (Lib) messages: 390778 nosy: kormang priority: normal severity: normal status: open title: asyncio.StreamReader hangs when reading from pipe and other process exits unexpectedly versions: Python 3.8 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue43806> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com