File tree Expand file tree Collapse file tree 2 files changed +5
-18
lines changed Expand file tree Collapse file tree 2 files changed +5
-18
lines changed Original file line number Diff line number Diff line change 1- import atexit
21import os
2+ import weakref
33from typing import List , Optional
44
55import msgspec
@@ -165,15 +165,9 @@ def __init__(
165165 ready_path = ready_path , # type: ignore[misc]
166166 ** kwargs ,
167167 )
168- atexit . register ( self .shutdown )
168+ self . _finalizer = weakref . finalize ( self , self .shutdown )
169169
170170 def shutdown (self ):
171- # During final garbage collection in process shutdown, atexit may be
172- # None.
173- if atexit :
174- # in case shutdown gets called via __del__ first
175- atexit .unregister (self .shutdown )
176-
177171 # Shut down the zmq context.
178172 self .ctx .destroy (linger = 0 )
179173
@@ -197,9 +191,6 @@ def shutdown(self):
197191 os .remove (socket_file )
198192 self .proc_handle = None
199193
200- def __del__ (self ):
201- self .shutdown ()
202-
203194
204195class SyncMPClient (MPClient ):
205196 """Synchronous client for multi-proc EngineCore."""
Original file line number Diff line number Diff line change 1- import atexit
21import os
32import pickle
43import signal
54import sys
65import time
6+ import weakref
77from dataclasses import dataclass
88from enum import Enum , auto
99from multiprocessing .process import BaseProcess
@@ -37,7 +37,7 @@ class MultiprocExecutor(Executor):
3737 def __init__ (self , vllm_config : VllmConfig ) -> None :
3838 # Call self.shutdown at exit to clean up
3939 # and ensure workers will be terminated.
40- atexit . register ( self .shutdown )
40+ self . _finalizer = weakref . finalize ( self , self .shutdown )
4141
4242 self .vllm_config = vllm_config
4343 self .parallel_config = vllm_config .parallel_config
@@ -195,14 +195,10 @@ def _cleanup_sockets(self):
195195 os .remove (socket_path )
196196
197197 def shutdown (self ):
198- if atexit :
199- # in case shutdown was called explicitly, we don't need to call it
200- # again
201- atexit .unregister (self .shutdown )
202198 """Properly shut down the executor and its workers"""
203199 if getattr (self , 'shutting_down' , False ):
204200 self .shutting_down = True
205- for w in self .workers : #TODO: not sure if needed
201+ for w in self .workers :
206202 w .worker_response_mq = None
207203 self ._ensure_worker_termination ()
208204
You can’t perform that action at this time.
0 commit comments