From 2210f50039bdd349594c99d6ac6fa923c6c10aa8 Mon Sep 17 00:00:00 2001 From: Chris Cummins Date: Mon, 7 Mar 2022 19:32:19 +0000 Subject: [PATCH] [service] Defend against logging error on close(). --- compiler_gym/service/connection_pool.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/compiler_gym/service/connection_pool.py b/compiler_gym/service/connection_pool.py index 37d9ce4030..96ac5642b6 100644 --- a/compiler_gym/service/connection_pool.py +++ b/compiler_gym/service/connection_pool.py @@ -174,11 +174,18 @@ def close(self) -> None: if self.closed: return - logger.debug( - "Closing the service connection pool with %d cached and %d live connections", - self.size, - len(self.allocated), - ) + try: + logger.debug( + "Closing the service connection pool with %d cached and %d live connections", + self.size, + len(self.allocated), + ) + except ValueError: + # As this method is invoked by the atexit callback, the logger + # may already have closed its streams, in which case a + # ValueError is raised. + pass + for connections in self.pool.values(): for connection in connections: connection.shutdown()