Skip to content

Commit 17e16bb

Browse files
Pathways-on-Cloud Teamcopybara-github
authored andcommitted
Ensure that the proxy client exits cleanly
PiperOrigin-RevId: 862897107
1 parent f7a40f8 commit 17e16bb

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

pathwaysutils/experimental/shared_pathways_service/isc_pathways.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from collections.abc import Iterator, Mapping
44
import contextlib
5+
import gc
56
import logging
67
import os
78
import random
@@ -10,6 +11,7 @@
1011
from typing import Any
1112

1213
import jax
14+
import jax.extend.backend as jax_backend
1315
import pathwaysutils
1416
from pathwaysutils.experimental.shared_pathways_service import gke_utils
1517
from pathwaysutils.experimental.shared_pathways_service import validators
@@ -177,7 +179,16 @@ def __exit__(self, exc_type, exc_value, traceback):
177179

178180
def _cleanup(self):
179181
"""Cleans up resources created by the ISCPathways context."""
182+
# 1. Clear JAX caches and run garbage collection.
183+
_logger.info("Starting Pathways proxy cleanup.")
184+
jax_backend.clear_backends()
185+
jax.clear_caches()
186+
gc.collect()
187+
_logger.info("Cleared JAX caches and ran garbage collection.")
188+
189+
# 2. Terminate the port forwarding process.
180190
if self._port_forward_process:
191+
_logger.info("Terminating port forwarding process...")
181192
self._port_forward_process.terminate()
182193
try:
183194
self._port_forward_process.wait(timeout=10)
@@ -188,8 +199,10 @@ def _cleanup(self):
188199
e,
189200
)
190201

191-
_logger.info("Deleting Pathways proxy")
202+
# 3. Delete the proxy GKE job.
203+
_logger.info("Deleting Pathways proxy...")
192204
gke_utils.delete_gke_job(self._proxy_job_name)
205+
_logger.info("Pathways proxy GKE job deletion complete.")
193206

194207

195208
@contextlib.contextmanager

0 commit comments

Comments
 (0)