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()