This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author kormang
Recipients kormang
Date 2021-04-11.12:17:49
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1618143469.5.0.154132734242.issue43806@roundup.psfhosted.org>
In-reply-to
Content
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())
History
Date User Action Args
2021-04-11 12:17:49kormangsetrecipients: + kormang
2021-04-11 12:17:49kormangsetmessageid: <1618143469.5.0.154132734242.issue43806@roundup.psfhosted.org>
2021-04-11 12:17:49kormanglinkissue43806 messages
2021-04-11 12:17:49kormangcreate