1313import subprocess
1414import time
1515from random import randint
16- from typing import Any
16+ from typing import Any , ClassVar
1717
1818from jupyter_client import localinterfaces
1919from jupyter_server .utils import url_unescape
@@ -32,8 +32,8 @@ class ConductorClusterProcessProxy(RemoteProcessProxy):
3232 Kernel lifecycle management for Conductor clusters.
3333 """
3434
35- initial_states = {"SUBMITTED" , "WAITING" , "RUNNING" }
36- final_states = {"FINISHED" , "KILLED" , "RECLAIMED" } # Don't include FAILED state
35+ initial_states : ClassVar = {"SUBMITTED" , "WAITING" , "RUNNING" }
36+ final_states : ClassVar = {"FINISHED" , "KILLED" , "RECLAIMED" } # Don't include FAILED state
3737
3838 def __init__ (self , kernel_manager : RemoteKernelManager , proxy_config : dict ):
3939 """Initialize the proxy."""
@@ -227,9 +227,7 @@ def _update_notebook_master_rest_url(self, env_dict: dict) -> None:
227227
228228 if updated_one_notebook_master_rest_url and updated_one_notebook_master_web_submission_url :
229229 self .log .debug (
230- "Updating KERNEL_NOTEBOOK_MASTER_REST to '{}'." .format (
231- updated_one_notebook_master_rest_url
232- )
230+ f"Updating KERNEL_NOTEBOOK_MASTER_REST to '{ updated_one_notebook_master_rest_url } '."
233231 )
234232 os .environ ["KERNEL_NOTEBOOK_MASTER_REST" ] = updated_one_notebook_master_rest_url
235233 env_dict ["KERNEL_NOTEBOOK_MASTER_REST" ] = updated_one_notebook_master_rest_url
@@ -416,9 +414,7 @@ async def handle_timeout(self) -> None:
416414 )
417415
418416 if time_interval > self .kernel_launch_timeout :
419- reason = "Application failed to start within {} seconds." .format (
420- self .kernel_launch_timeout
421- )
417+ reason = f"Application failed to start within { self .kernel_launch_timeout } seconds."
422418 error_http_code = 500
423419 if self ._get_application_id (True ):
424420 if self ._query_app_state_by_driver_id (self .driver_id ) != "WAITING" :
@@ -435,9 +431,7 @@ async def handle_timeout(self) -> None:
435431 self .application_id , self .kernel_launch_timeout
436432 )
437433 await asyncio .get_event_loop ().run_in_executor (None , self .kill )
438- timeout_message = "KernelID: '{}' launch timeout due to: {}" .format (
439- self .kernel_id , reason
440- )
434+ timeout_message = f"KernelID: '{ self .kernel_id } ' launch timeout due to: { reason } "
441435 self .log_and_raise (http_status_code = error_http_code , reason = timeout_message )
442436
443437 def _get_application_id (self , ignore_final_states : bool = False ) -> str :
@@ -473,9 +467,7 @@ def _get_application_id(self, ignore_final_states: bool = False) -> str:
473467 )
474468 else :
475469 self .log .debug (
476- "ApplicationID not yet assigned for KernelID: '{}' - retrying..." .format (
477- self .kernel_id
478- )
470+ f"ApplicationID not yet assigned for KernelID: '{ self .kernel_id } ' - retrying..."
479471 )
480472 return self .application_id
481473
@@ -525,9 +517,7 @@ def _query_app_by_driver_id(self, driver_id: str) -> dict | None:
525517 response = None if not response or not response ["applist" ] else response ["applist" ]
526518 except Exception as e :
527519 self .log .warning (
528- "Getting application with cmd '{}' failed with exception: '{}'. Continuing..." .format (
529- cmd , e
530- )
520+ f"Getting application with cmd '{ cmd } ' failed with exception: '{ e } '. Continuing..."
531521 )
532522 return response
533523
@@ -557,9 +547,7 @@ def _query_app_by_id(self, app_id: str) -> dict | None:
557547 response = None if response is None or not response ["applist" ] else response ["applist" ]
558548 except Exception as e :
559549 self .log .warning (
560- "Getting application with cmd '{}' failed with exception: '{}'. Continuing..." .format (
561- cmd , e
562- )
550+ f"Getting application with cmd '{ cmd } ' failed with exception: '{ e } '. Continuing..."
563551 )
564552 return response
565553
0 commit comments