forked from M-Labs/artiq
protocols/pipe_ipc: fix read transport resource leak
This caused the "Exception ignored in:" message on exit.
This commit is contained in:
parent
29d4755567
commit
4a03335850
|
@ -24,17 +24,14 @@ if os.name != "nt":
|
||||||
async def _fds_to_asyncio(rfd, wfd, loop):
|
async def _fds_to_asyncio(rfd, wfd, loop):
|
||||||
reader = asyncio.StreamReader(loop=loop)
|
reader = asyncio.StreamReader(loop=loop)
|
||||||
reader_protocol = asyncio.StreamReaderProtocol(reader, loop=loop)
|
reader_protocol = asyncio.StreamReaderProtocol(reader, loop=loop)
|
||||||
|
rf = open(rfd, "rb", 0)
|
||||||
|
rt, _ = await loop.connect_read_pipe(lambda: reader_protocol, rf)
|
||||||
|
|
||||||
wf = open(wfd, "wb", 0)
|
wf = open(wfd, "wb", 0)
|
||||||
transport, _ = await loop.connect_write_pipe(
|
wt, _ = await loop.connect_write_pipe(FlowControlMixin, wf)
|
||||||
FlowControlMixin, wf)
|
writer = asyncio.StreamWriter(wt, reader_protocol, None, loop)
|
||||||
writer = asyncio.StreamWriter(transport, reader_protocol,
|
|
||||||
None, loop)
|
|
||||||
|
|
||||||
rf = open(rfd, "rb", 0)
|
return rt, reader, writer
|
||||||
await loop.connect_read_pipe(lambda: reader_protocol, rf)
|
|
||||||
|
|
||||||
return reader, writer
|
|
||||||
|
|
||||||
|
|
||||||
class AsyncioParentComm(_BaseIO):
|
class AsyncioParentComm(_BaseIO):
|
||||||
|
@ -47,6 +44,7 @@ if os.name != "nt":
|
||||||
|
|
||||||
async def _autoclose(self):
|
async def _autoclose(self):
|
||||||
await self.process.wait()
|
await self.process.wait()
|
||||||
|
self.reader_transport.close()
|
||||||
self.writer.close()
|
self.writer.close()
|
||||||
|
|
||||||
async def create_subprocess(self, *args, **kwargs):
|
async def create_subprocess(self, *args, **kwargs):
|
||||||
|
@ -56,8 +54,8 @@ if os.name != "nt":
|
||||||
os.close(self.c_rfd)
|
os.close(self.c_rfd)
|
||||||
os.close(self.c_wfd)
|
os.close(self.c_wfd)
|
||||||
|
|
||||||
self.reader, self.writer = await _fds_to_asyncio(
|
self.reader_transport, self.reader, self.writer = \
|
||||||
self.p_rfd, self.p_wfd, loop)
|
await _fds_to_asyncio(self.p_rfd, self.p_wfd, loop)
|
||||||
asyncio.ensure_future(self._autoclose())
|
asyncio.ensure_future(self._autoclose())
|
||||||
|
|
||||||
|
|
||||||
|
@ -67,10 +65,12 @@ if os.name != "nt":
|
||||||
|
|
||||||
async def connect(self):
|
async def connect(self):
|
||||||
rfd, wfd = self.address.split(",", maxsplit=1)
|
rfd, wfd = self.address.split(",", maxsplit=1)
|
||||||
self.reader, self.writer = await _fds_to_asyncio(
|
self.reader_transport, self.reader, self.writer = \
|
||||||
int(rfd), int(wfd), asyncio.get_event_loop())
|
await _fds_to_asyncio(int(rfd), int(wfd),
|
||||||
|
asyncio.get_event_loop())
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
|
self.reader_transport.close()
|
||||||
self.writer.close()
|
self.writer.close()
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue