Fix non-exception-safe finally: handlers.

Fixes #1013.
This commit is contained in:
whitequark 2018-05-25 04:23:32 +00:00
parent 44910efd0a
commit 223b984385
2 changed files with 5 additions and 2 deletions

View File

@ -168,6 +168,7 @@ class LogForwarder(logging.Handler, TaskObject):
self._queue.put_nowait(record.source + ":" + self.format(record)) self._queue.put_nowait(record.source + ":" + self.format(record))
async def _do(self): async def _do(self):
reader = writer = None
while True: while True:
try: try:
reader, writer = await asyncio.open_connection(self.host, reader, writer = await asyncio.open_connection(self.host,
@ -182,4 +183,5 @@ class LogForwarder(logging.Handler, TaskObject):
except: except:
await asyncio.sleep(self.reconnect_timer) await asyncio.sleep(self.reconnect_timer)
finally: finally:
writer.close() if writer is not None:
writer.close()

View File

@ -243,7 +243,8 @@ class AsyncioClient:
No further method calls should be done after this method is called. 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.__reader = None
self.__writer = None self.__writer = None
self.__target_names = None self.__target_names = None