@@ -522,6 +522,7 @@ def __init__(
522522 self .streaming_input_queue = streaming_input_queue
523523 self .streaming_output_queue = streaming_output_queue
524524 self ._initial_log_handler = _initial_log_handler
525+ self ._shutdown_started = False
525526 self ._shutdown_complete = False
526527 self ._shutdown_response : dict [str , Any ] | None = None
527528 wrapper = WorkerWrapperBase (fastvideo_args = fastvideo_args , rpc_rank = rank )
@@ -719,10 +720,26 @@ def shutdown(self) -> dict[str, Any]:
719720 assert self ._shutdown_response is not None
720721 return self ._shutdown_response
721722
722- response = self .worker .shutdown ()
723- _shutdown_torch_compile_workers ()
724- self ._shutdown_response = response
725- self ._shutdown_complete = True
723+ if getattr (self , "_shutdown_started" , False ):
724+ if self ._shutdown_response is None :
725+ self ._shutdown_response = {"status" : "shutdown" }
726+ return self ._shutdown_response
727+
728+ self ._shutdown_started = True
729+ response = {"status" : "shutdown" }
730+ shutdown_succeeded = False
731+
732+ try :
733+ response = self .worker .shutdown ()
734+ shutdown_succeeded = True
735+ except Exception :
736+ logger .exception ("Worker %d failed to shut down" , self .rank )
737+ finally :
738+ _shutdown_torch_compile_workers ()
739+ if shutdown_succeeded :
740+ self ._shutdown_complete = True
741+ self ._shutdown_response = response
742+
726743 return response
727744
728745 def worker_busy_loop (self ) -> None :
0 commit comments