diff --git a/artiq/protocols/logging.py b/artiq/protocols/logging.py index 61b9c07fb..6333942da 100644 --- a/artiq/protocols/logging.py +++ b/artiq/protocols/logging.py @@ -117,11 +117,19 @@ class LogForwarder(logging.Handler, TaskObject): try: reader, writer = await asyncio.open_connection(self.host, self.port) + detect_close = asyncio.ensure_future(reader.read(1)) writer.write(_init_string) while True: message = await self._queue.get() + "\n" writer.write(message.encode()) await writer.drain() + # HACK: detect connection termination through the completion + # of a read operation. For some reason, write/drain operations + # on a closed socket do not raise exceptions, but print + # "asyncio:socket.send() raised exception." + if detect_close.done(): + await asyncio.sleep(self.reconnect_timer) + break except asyncio.CancelledError: return except: