From c5a60d4cce86568a66e803e98b7a3ef557b01bbb Mon Sep 17 00:00:00 2001 From: Zongheng Yang Date: Sat, 10 Jun 2023 21:02:38 -0700 Subject: [PATCH] API: fix a possibly unbound error in core.cancel(). (#2061) Core: fix a possibly unbound error in core.cancel(). --- sky/core.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sky/core.py b/sky/core.py index af3d408dcf9..90fe1f4596d 100644 --- a/sky/core.py +++ b/sky/core.py @@ -560,6 +560,7 @@ def cancel( cluster_name, operation_str='Cancelling jobs') # Check the status of the cluster. + handle = None try: handle = backend_utils.check_cluster_available( cluster_name, @@ -572,11 +573,15 @@ def cancel( isinstance(e.handle, backends.CloudVmRayResourceHandle)), e if (e.handle is None or e.handle.head_ip is None): raise + handle = e.handle # Even if the cluster is not UP, we can still try to cancel the job if # the head node is still alive. This is useful when a spot cluster's # worker node is preempted, but we can still cancel the job on the head # node. + assert handle is not None, ( + f'handle for cluster {cluster_name!r} should not be None') + backend = backend_utils.get_backend_from_handle(handle) if all: