forked from M-Labs/artiq
protocols/pipe_ipc: fix resource leak on Windows
This commit is contained in:
parent
5fad570f5e
commit
b0526c3354
|
@ -109,7 +109,6 @@ else: # windows
|
||||||
# mode or not.
|
# mode or not.
|
||||||
self.address = "\\\\.\\pipe\\artiq-{}-{}".format(os.getpid(),
|
self.address = "\\\\.\\pipe\\artiq-{}-{}".format(os.getpid(),
|
||||||
next(_pipe_count))
|
next(_pipe_count))
|
||||||
self.server = None
|
|
||||||
self.ready = asyncio.Event()
|
self.ready = asyncio.Event()
|
||||||
self.write_buffer = b""
|
self.write_buffer = b""
|
||||||
|
|
||||||
|
@ -118,11 +117,12 @@ else: # windows
|
||||||
|
|
||||||
async def _autoclose(self):
|
async def _autoclose(self):
|
||||||
await self.process.wait()
|
await self.process.wait()
|
||||||
if self.server is not None:
|
self.server[0].close()
|
||||||
self.server[0].close()
|
del self.server
|
||||||
self.server = None
|
|
||||||
if self.ready.is_set():
|
if self.ready.is_set():
|
||||||
self.writer.close()
|
self.writer.close()
|
||||||
|
del self.reader
|
||||||
|
del self.writer
|
||||||
|
|
||||||
async def create_subprocess(self, *args, **kwargs):
|
async def create_subprocess(self, *args, **kwargs):
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
|
@ -150,8 +150,12 @@ else: # windows
|
||||||
# There is still a race condition in the AsyncioParentComm
|
# There is still a race condition in the AsyncioParentComm
|
||||||
# creation/destruction, but it is unlikely to cause problems
|
# creation/destruction, but it is unlikely to cause problems
|
||||||
# in most practical cases.
|
# in most practical cases.
|
||||||
assert self.server is not None
|
if self.ready.is_set():
|
||||||
self.server = None
|
# A child already connected before. We should have shut down
|
||||||
|
# the server, but asyncio won't let us do that.
|
||||||
|
# Drop connections immediately instead.
|
||||||
|
writer.close()
|
||||||
|
return
|
||||||
self.reader = reader
|
self.reader = reader
|
||||||
self.writer = writer
|
self.writer = writer
|
||||||
if self.write_buffer:
|
if self.write_buffer:
|
||||||
|
|
Loading…
Reference in New Issue