Message390778
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()) |
|
Date |
User |
Action |
Args |
2021-04-11 12:17:49 | kormang | set | recipients:
+ kormang |
2021-04-11 12:17:49 | kormang | set | messageid: <1618143469.5.0.154132734242.issue43806@roundup.psfhosted.org> |
2021-04-11 12:17:49 | kormang | link | issue43806 messages |
2021-04-11 12:17:49 | kormang | create | |
|