shut down pipes correctly, refs #146

This commit is contained in:
Jakob Ketterl 2020-07-19 19:42:18 +02:00
parent c54f19282a
commit 369a61ec59
1 changed files with 15 additions and 0 deletions

View File

@ -146,6 +146,9 @@ class WebSocketConnection(object):
self.close()
def interrupt(self):
if self.interruptPipeSend is None:
logger.debug("interrupt with closed pipe")
return
self.interruptPipeSend.send(bytes(0x00))
def handle(self):
@ -227,6 +230,18 @@ class WebSocketConnection(object):
logger.exception("OSError while reading data; closing connection")
self.open = False
self.interruptPipeSend.close()
self.interruptPipeSend = None
# drain messages left in the queue so that the queue can be successfully closed
# this is necessary since python keeps the file descriptors open otherwise
try:
while True:
self.interruptPipeRecv.recv()
except EOFError:
pass
self.interruptPipeRecv.close()
self.interruptPipeRecv = None
def close(self):
self.open = False
self.interrupt()