From 223b984385defb84a0829270ae14d65947ba5a86 Mon Sep 17 00:00:00 2001 From: whitequark Date: Fri, 25 May 2018 04:23:32 +0000 Subject: [PATCH] Fix non-exception-safe finally: handlers. Fixes #1013. --- artiq/protocols/logging.py | 4 +++- artiq/protocols/pc_rpc.py | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/artiq/protocols/logging.py b/artiq/protocols/logging.py index 5c282549a..542e8da35 100644 --- a/artiq/protocols/logging.py +++ b/artiq/protocols/logging.py @@ -168,6 +168,7 @@ class LogForwarder(logging.Handler, TaskObject): self._queue.put_nowait(record.source + ":" + self.format(record)) async def _do(self): + reader = writer = None while True: try: reader, writer = await asyncio.open_connection(self.host, @@ -182,4 +183,5 @@ class LogForwarder(logging.Handler, TaskObject): except: await asyncio.sleep(self.reconnect_timer) finally: - writer.close() + if writer is not None: + writer.close() diff --git a/artiq/protocols/pc_rpc.py b/artiq/protocols/pc_rpc.py index d99ca06fb..410cc8908 100644 --- a/artiq/protocols/pc_rpc.py +++ b/artiq/protocols/pc_rpc.py @@ -243,7 +243,8 @@ class AsyncioClient: No further method calls should be done after this method is called. """ - self.__writer.close() + if self.__writer is not None: + self.__writer.close() self.__reader = None self.__writer = None self.__target_names = None